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:
cgoldfeder 2016-06-14 20:58:57 -07:00 committed by Ben McIlwain
parent 6466ad51f6
commit ec39f15a23
31 changed files with 133 additions and 62 deletions

View file

@ -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