Search in sources :

Example 46 with XmlMapper

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;
}
Also used : JacksonXmlModule(com.fasterxml.jackson.dataformat.xml.JacksonXmlModule) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Example 47 with XmlMapper

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);
}
Also used : XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper) Test(org.junit.jupiter.api.Test)

Example 48 with XmlMapper

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BadRequestException(ninja.exceptions.BadRequestException) IOException(java.io.IOException) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper) Test(org.junit.Test)

Example 49 with XmlMapper

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;
}
Also used : AfterburnerModule(com.fasterxml.jackson.module.afterburner.AfterburnerModule) JacksonXmlModule(com.fasterxml.jackson.dataformat.xml.JacksonXmlModule) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Example 50 with 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());
}
Also used : JacksonXmlModule(com.fasterxml.jackson.dataformat.xml.JacksonXmlModule) ArticlesDto(models.ArticlesDto) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper) ArticleDto(models.ArticleDto) Test(org.junit.Test) NinjaTest(ninja.NinjaTest)

Aggregations

XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)62 IOException (java.io.IOException)19 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)15 Test (org.junit.Test)15 InputStream (java.io.InputStream)9 File (java.io.File)8 HttpResponse (org.apache.http.HttpResponse)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)7 JacksonXmlModule (com.fasterxml.jackson.dataformat.xml.JacksonXmlModule)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Test (org.junit.jupiter.api.Test)5 BadRequestException (ninja.exceptions.BadRequestException)4 EntityReferences (org.apache.cloudstack.backup.veeam.api.EntityReferences)4 Ref (org.apache.cloudstack.backup.veeam.api.Ref)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 AfterburnerModule (com.fasterxml.jackson.module.afterburner.AfterburnerModule)2 FileInputStream (java.io.FileInputStream)2