@SuppressWarnings("unchecked")
@Override
public T read(HttpResponseMessage httpResponseMessage, Type expectedType) {
Class<T> expectedClassType = (Class<T>) expectedType;
JAXBContext context = contextOf(expectedClassType);
try {
Unmarshaller unmarshaller = context.createUnmarshaller();
StreamSource source = new StreamSource(httpResponseMessage.body());
XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(source);
return expectedClassType.isAnnotationPresent(XmlRootElement.class) ? (T) unmarshaller.unmarshal(reader)
: unmarshaller.unmarshal(reader, expectedClassType).getValue();
} catch (JAXBException | XMLStreamException | FactoryConfigurationError e) {
throw new RestifyHttpMessageReadException("Error on try read xml message", e);
}
}
JaxbXmlMessageConverter.java 文件源码
java
阅读 20
收藏 0
点赞 0
评论 0
项目:java-restify
作者:
评论列表
文章目录