mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 07:57:13 +02:00
Fix generics in EppXmlTransformer.unmarshal to not be only on the return type.
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=124914271
This commit is contained in:
parent
6466ad51f6
commit
ec39f15a23
31 changed files with 133 additions and 62 deletions
|
@ -136,21 +136,19 @@ public class XmlTransformer {
|
|||
}
|
||||
|
||||
/**
|
||||
* Turns XML text into an object, validating against {@link #schema}.
|
||||
*
|
||||
* <p>You must specify the XML class you expect to receive as the root element. Validation is
|
||||
* performed in accordance with the hard-coded XML schemas.
|
||||
* Turns XML text into an object, validating against hard-coded xml {@link #schema}s.
|
||||
*
|
||||
* @param clazz the XML class you expect to receive as the root element
|
||||
* @throws XmlException if failed to read from {@code bytes}, XML input is invalid, or root
|
||||
* element doesn't match {@code expect}.
|
||||
* @see com.google.common.io.Files#asByteSource
|
||||
* @see com.google.common.io.Resources#asByteSource
|
||||
* @see "http://errorprone.info/bugpattern/TypeParameterUnusedInFormals"
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T unmarshal(InputStream stream) throws XmlException {
|
||||
public <T> T unmarshal(Class<T> clazz, InputStream stream) throws XmlException {
|
||||
try (InputStream autoClosingStream = stream) {
|
||||
return (T) getUnmarshaller().unmarshal(
|
||||
XML_INPUT_FACTORY.createXMLStreamReader(new StreamSource(autoClosingStream, SYSTEM_ID)));
|
||||
return clazz.cast(getUnmarshaller().unmarshal(
|
||||
XML_INPUT_FACTORY.createXMLStreamReader(new StreamSource(autoClosingStream, SYSTEM_ID))));
|
||||
} catch (UnmarshalException e) {
|
||||
// Plain old parsing exceptions have a SAXParseException with no further cause.
|
||||
if (e.getLinkedException() instanceof SAXParseException
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue