Package com.fasterxml.jackson.dataformat.xml

Examples of com.fasterxml.jackson.dataformat.xml.XmlMapper


public class ToolSuiteXmlParsingTests {
    private String responseXml = Fixtures.load("/fixtures/tools/sts_downloads.xml");

    @Test
    public void unmarshal() throws Exception {
        XmlMapper serializer = new XmlMapper();

        ToolSuiteXml toolSuiteXml = serializer.readValue(responseXml, ToolSuiteXml.class);
        assertThat(toolSuiteXml.getReleases(), notNullValue());
        assertThat(toolSuiteXml.getReleases().size(), equalTo(4));
        Release release = toolSuiteXml.getReleases().get(0);
        assertThat(release.getDownloads().size(), equalTo(7));
        assertThat(release.getWhatsnew(), notNullValue());
View Full Code Here


    private CachedRestClient restClient;

    @SuppressWarnings("unchecked")
    @Before
    public void setUp() throws Exception {
        XmlMapper serializer = new XmlMapper();
        service = new ToolsService(restClient, restTemplate, serializer);
        String responseXml = Fixtures.load("/fixtures/tools/sts_downloads.xml");
        when(restClient.get(eq(restTemplate), anyString(), (Class<String>) anyObject())).thenReturn(responseXml);
    }
View Full Code Here

        return new ObjectMapper();
    }

    @Bean
    public XmlMapper xmlMapper() {
        return new XmlMapper();
    }
View Full Code Here

  }

  @Test
  public void renderWithCustomSerializerLocatedByFactory() throws Exception {
    SerializerFactory factory = new DelegatingSerializerFactory(null);
    XmlMapper mapper = new XmlMapper();
    mapper.setSerializerFactory(factory);
    view.setObjectMapper(mapper);

    Object bean = new TestBeanSimple();
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("foo", bean);
View Full Code Here

    assertTrue(objectMapper.getSerializationConfig().getSerializationInclusion() == JsonInclude.Include.NON_NULL);
  }

  @Test
  public void xmlMapper() {
    this.factory.setObjectMapper(new XmlMapper());
    this.factory.afterPropertiesSet();

    assertNotNull(this.factory.getObject());
    assertTrue(this.factory.isSingleton());
    assertEquals(XmlMapper.class, this.factory.getObjectType());
View Full Code Here

     */
    @Override
    public XmlMapper _locateMapperViaProvider(Class<?> type, MediaType mediaType)
    {
        // First: were we configured with a specific instance?
        XmlMapper m = _mapperConfig.getConfiguredMapper();
        if (m == null) {
            // If not, maybe we can get one configured via context?
            if (_providers != null) {
                ContextResolver<XmlMapper> resolver = _providers.getContextResolver(XmlMapper.class, mediaType);
                /* Above should work as is, but due to this bug
View Full Code Here

                .postXml(getServerAddress() + "api/person.xml", person);
       
        System.out.println("j: " + response);


        Person result = new XmlMapper().readValue(response, Person.class);
        assertEquals(person.name, result.name);
    }
View Full Code Here

        // 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;
       
    }
View Full Code Here

            httpClient.getParams().setParameter(
                    CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);

            HttpPost post = new HttpPost(url);
            StringEntity entity = new StringEntity(
                    new XmlMapper().writeValueAsString(object), "utf-8");
            entity.setContentType("application/xml; charset=utf-8");
            post.setEntity(entity);
            post.releaseConnection();

            // Here we go!
View Full Code Here

        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());

    }
View Full Code Here

TOP

Related Classes of com.fasterxml.jackson.dataformat.xml.XmlMapper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.