use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project ihmc-pub-sub by ihmcrobotics.
the class XMLSerializer method createXMLObjectMapper.
private static ObjectMapper createXMLObjectMapper() {
JacksonXmlModule module = new JacksonXmlModule();
module.setDefaultUseWrapper(false);
XmlMapper objectMapper = new XmlMapper(module);
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
return objectMapper;
}
use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project spring-framework by spring-projects.
the class Jackson2ObjectMapperFactoryBeanTests method setObjectMapper.
@Test
public void setObjectMapper() {
this.factory.setObjectMapper(new XmlMapper());
this.factory.afterPropertiesSet();
assertThat(this.factory.getObject()).isNotNull();
assertThat(this.factory.isSingleton()).isTrue();
assertThat(this.factory.getObjectType()).isEqualTo(XmlMapper.class);
}
use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project ninja by ninjaframework.
the class BodyParserEngineXmlTest method testXmlBodyWithMissingVariables.
@Test
public void testXmlBodyWithMissingVariables() {
final String xmlDocument = String.format("<form><firstName>%s</firstName><lastName>%s</lastName></form>", BodyParserEngineXmlTest.DATA_FIRSTNAME, BodyParserEngineXmlTest.DATA_LASTNAME);
final InputStream is = new ByteArrayInputStream(xmlDocument.getBytes());
final XmlMapper xmlObjMapper = new XmlMapper();
final BodyParserEngineXml bodyParserEngineXml = new BodyParserEngineXml(xmlObjMapper);
SimpleTestForm testForm = null;
try {
Mockito.when(context.getInputStream()).thenReturn(is);
} catch (IOException ignore) {
}
try {
testForm = bodyParserEngineXml.invoke(context, SimpleTestForm.class);
} catch (BadRequestException ignore) {
} finally {
try {
is.close();
} catch (IOException ignore) {
}
}
assertTrue(testForm != null);
assertThat(testForm.firstName, equalTo(BodyParserEngineXmlTest.DATA_FIRSTNAME));
assertThat(testForm.lastName, equalTo(BodyParserEngineXmlTest.DATA_LASTNAME));
assertTrue(testForm.birthYear == null);
assertTrue(testForm.lastSeen == null);
}
use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project ninja by ninjaframework.
the class XmlMapperProvider method get.
@Override
public XmlMapper get() {
JacksonXmlModule module = new JacksonXmlModule();
// Check out: https://github.com/FasterXML/jackson-dataformat-xml
// setDefaultUseWrapper produces more similar output to
// the Json output. You can change that with annotations in your
// models.
module.setDefaultUseWrapper(false);
XmlMapper xmlMapper = new XmlMapper(module);
xmlMapper.registerModule(new AfterburnerModule());
return xmlMapper;
}
use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project ninja by ninjaframework.
the class ApiControllerTest method testGetAndPostArticleViaXml.
@Test
public void testGetAndPostArticleViaXml() throws Exception {
// /////////////////////////////////////////////////////////////////////
// Test initial data:
// /////////////////////////////////////////////////////////////////////
String response = ninjaTestBrowser.makeXmlRequest(getServerAddress() + "api/bob@gmail.com/articles.xml");
System.out.println("response xml: " + response);
JacksonXmlModule module = new JacksonXmlModule();
// and then configure, for example:
module.setDefaultUseWrapper(false);
XmlMapper xmlMapper = new XmlMapper(module);
ArticlesDto articlesDto = xmlMapper.readValue(response, ArticlesDto.class);
assertEquals(3, articlesDto.articles.size());
// /////////////////////////////////////////////////////////////////////
// Post new article:
// /////////////////////////////////////////////////////////////////////
ArticleDto articleDto = new ArticleDto();
articleDto.content = "contentcontent";
articleDto.title = "new title new title";
response = ninjaTestBrowser.postXml(getServerAddress() + "api/bob@gmail.com/article.xml", articleDto);
assertTrue(response.contains("Error. Forbidden."));
doLogin();
response = ninjaTestBrowser.postXml(getServerAddress() + "api/bob@gmail.com/article.xml", articleDto);
assertFalse(response.contains("Error. Forbidden."));
// /////////////////////////////////////////////////////////////////////
// Fetch articles again => assert we got a new one ...
// /////////////////////////////////////////////////////////////////////
response = ninjaTestBrowser.makeXmlRequest(getServerAddress() + "api/bob@gmail.com/articles.xml");
articlesDto = xmlMapper.readValue(response, ArticlesDto.class);
// one new result:
assertEquals(4, articlesDto.articles.size());
}
Aggregations