本文整理汇总了Java中javax.xml.bind.Unmarshaller.setProperty方法的典型用法代码示例。如果您正苦于以下问题:Java Unmarshaller.setProperty方法的具体用法?Java Unmarshaller.setProperty怎么用?Java Unmarshaller.setProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.bind.Unmarshaller
的用法示例。
在下文中一共展示了Unmarshaller.setProperty方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readFrom
import javax.xml.bind.Unmarshaller; //导入方法依赖的package包/类
public AccessToken readFrom(Class<AccessToken> type, Type genericType, Annotation[] annotations,
MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
throws IOException, WebApplicationException {
try {
JAXBContext jc = JAXBContext.newInstance(AccessToken.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
// Set it to true if you need to include the JSON root element in
// the
// JSON input
unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
StreamSource streamSource = new StreamSource(entityStream);
AccessToken accessToken = unmarshaller.unmarshal(streamSource, AccessToken.class).getValue();
return accessToken;
} catch (JAXBException e) {
LOG.error("can't unmarshall response",e);
throw new RuntimeException("can't unmarshall response");
}
}
示例2: testUnmarschallingMessage
import javax.xml.bind.Unmarshaller; //导入方法依赖的package包/类
@Test
public void testUnmarschallingMessage() throws Exception{
JAXBContext jc = JAXBContext.newInstance(Message.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
// Set it to true if you need to include the JSON root element in
// the
// JSON input
unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
String json = "{\"message\":\"success\"}";
StreamSource stream =
new StreamSource(new StringReader(json));
Message message = unmarshaller.unmarshal(stream, Message.class).getValue();
Assert.assertNotNull(message);
Assert.assertTrue(message.getMessage().equals("success"));
}
示例3: testUnmarschallingAccessToken
import javax.xml.bind.Unmarshaller; //导入方法依赖的package包/类
/**
* test unmarschalling of AccessToken
*
* @throws Exception
*/
@Test
public void testUnmarschallingAccessToken() throws Exception {
JAXBContext jc = JAXBContext.newInstance(AccessToken.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
// Set it to true if you need to include the JSON root element in
// the
// JSON input
unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
String json = "{\"access_token\":\"eyJhbGciOiJSU\""
+ " ,\"expires_in\":60,\"refresh_expires_in\":600," +
"\"refresh_token\":\"eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lk\"," +
"\"not-before-policy\":0,\"session_state\":\"a1f9f252-ff0f-4a45-bb9c-bec019eab79a\"}";
LOG.info("ummarshall token:" + json);
StreamSource stream =
new StreamSource(new StringReader(json));
AccessToken accessToken = unmarshaller.unmarshal(stream, AccessToken.class).getValue();
Assert.assertNotNull(accessToken);
}
示例4: readLibrary
import javax.xml.bind.Unmarshaller; //导入方法依赖的package包/类
private Library readLibrary(InputStream is) throws JAXBException {
//JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class.getPackage().getName(), ObjectFactory.class.getClassLoader());
JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
jaxbUnmarshaller.setProperty("com.sun.xml.bind.ObjectFactory", new ObjectFactoryEx());
// com.sun.xml.internal.bind.ObjectFactory causes javax.xml.bind.PropertyException
//Library library = (Library) jaxbUnmarshaller.unmarshal(is);
@SuppressWarnings("unchecked")
JAXBElement<Library> je = (JAXBElement<Library>) jaxbUnmarshaller.unmarshal(is);
Library library = je.getValue();
return library;
}
开发者ID:Discovery-Research-Network-SCCM,项目名称:FHIR-CQL-ODM-service,代码行数:14,代码来源:UsciitgLibraryManager.java
示例5: readFrom
import javax.xml.bind.Unmarshaller; //导入方法依赖的package包/类
public Message readFrom(Class<Message> type, Type genericType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
throws IOException, WebApplicationException {
try {
JAXBContext jc = JAXBContext.newInstance(Message.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
// unmarshaller.setProperty("javax.xml.bind.context.factory","org.eclipse.persistence.jaxb.JAXBContextFactory");
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
// Set it to true if you need to include the JSON root element in
// the
// JSON input
unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
unmarshaller.setProperty(UnmarshallerProperties.JSON_ATTRIBUTE_PREFIX, "@");
StreamSource streamSource = new StreamSource(entityStream);
Message message = unmarshaller.unmarshal(streamSource, Message.class).getValue();
return message;
} catch (JAXBException e) {
LOG.error("can't unmarshall response",e);
throw new RuntimeException("can't unmarshall response");
}
}
示例6: deserializeInternal
import javax.xml.bind.Unmarshaller; //导入方法依赖的package包/类
private <T> T deserializeInternal(StreamSource streamSource, Class<T> clazz) throws SerializerException {
try {
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
return unmarshaller.unmarshal(streamSource, clazz).getValue();
} catch (JAXBException e) {
log.error("Can't deserialize object of type {}", clazz.getSimpleName());
throw new SerializerException("Can't deserialize object of type " + clazz.getSimpleName(), e);
}
}