本文整理匯總了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);
}
}