Package com.fasterxml.jackson.dataformat.xml

Examples of com.fasterxml.jackson.dataformat.xml.XmlMapper.writeValueAsString()


        Issue66Bean node = mapper.readValue(XML, Issue66Bean.class);
        assertEquals("id", node.id);
        assertEquals("text", node.textValue);

        // Let's serialize too
        String json = mapper.writeValueAsString(node);
        assertEquals(XML, json);
    }

    // [Issue#72]
    public void testTextOnlyPojo() throws Exception
View Full Code Here


    private final XmlMapper MAPPER = new XmlMapper();
   
    public void testUntypedEnum() throws Exception
    {
        ObjectMapper mapper = new XmlMapper();
        String xml = mapper.writeValueAsString(new UntypedEnumBean(TestEnum.B));
       
        UntypedEnumBean result = mapper.readValue(xml, UntypedEnumBean.class);
        assertNotNull(result);
        assertNotNull(result.value);
        Object ob = result.value;
View Full Code Here

    public void testTextOnlyPojo() throws Exception
    {
        XmlMapper mapper = xmlMapper(true);
        TextOnlyWrapper input = new TextOnlyWrapper("foo", "bar");
        // serialization should work fine
        String xml = mapper.writeValueAsString(input);
        assertEquals("<TextOnlyWrapper><a>foo</a><b>bar</b></TextOnlyWrapper>", xml);
        // but how about deser?
        TextOnlyWrapper result = mapper.readValue(xml, TextOnlyWrapper.class);
        assertNotNull(result);
        assertEquals("foo", result.a.textValue);
View Full Code Here

        BeanInfo beanInfo = new BeanInfo("name");
        BeanInfo beanOther = new BeanInfo("name");
        bean.setBeanInfo(new BeanInfo[] { beanInfo });
        bean.setBeanOther(new BeanInfo[] { beanOther });

        String json = mapper.writeValueAsString(bean);
        assertNotNull(json);
//        System.out.println(output);
    }
}
View Full Code Here

    public void testCustomSerializer() throws Exception
    {
        JacksonXmlModule module = new JacksonXmlModule();
        module.addSerializer(String.class, new CustomSerializer());
        XmlMapper xml = new XmlMapper(module);
        assertEquals("<String>custom:foo</String>", xml.writeValueAsString("foo"));
    }
   
    // manual 'test' to see "what would JAXB do?"
    /*
    public void testJAXB() throws Exception
View Full Code Here

    {
        Person person = new Person();
        person.setName( "hello" );
       
        XmlMapper xmlMapper = new XmlMapper();
        String xml = xmlMapper.writeValueAsString(person);

        // should use "the default namespace"...
        final String PREFIX = "<person xmlns=";
        if (!xml.startsWith(PREFIX)) {
            fail("Expected XML to begin with '"+PREFIX+"', instead got: "+xml);
View Full Code Here

    public void testXmlTextWithSuppressedValue() throws Exception
    {
        final XmlMapper mapper = new XmlMapper();
        mapper.setSerializationInclusion(Include.NON_EMPTY);
        String xml = mapper.writeValueAsString(new Data("","second"));
        String expectedXml = "<Data><second>second</second></Data>";
        assertEquals(expectedXml, xml);
    }
}
View Full Code Here

        ObjectMapper mapper = new ObjectMapper();
        XmlMapper xmlMapper = new XmlMapper();
        ListPOJO list = new ListPOJO();
        list.v.add(new POJO(1, 2));
        list.v.add(new POJO(3, 4));
        String xml = xmlMapper.writeValueAsString(list);

        ObjectReader detecting = mapper.reader(ListPOJO.class);
        ListPOJO resultList = detecting
                .withFormatDetection(detecting, xmlMapper.reader(ListPOJO.class))
                .readValue(utf8Bytes(xml));
View Full Code Here

        MyPerson2 child = new MyPerson2();
        child.name = "Junior";
       
        person.child.add(child);

        String xml = jaxbMapper.writeValueAsString(person);
       
        String expected = "<p><name>Jay</name><child><name>Junior</name></child></p>";
        assertEquals(expected, xml);
    }
}
View Full Code Here

    public void testTwoAttributes() throws IOException
    {
        XmlMapper mapper = new XmlMapper();
//        mapper.setAnnotationIntrospector(new XmlJaxbAnnotationIntrospector(TypeFactory.defaultInstance()));
        mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()));
        String xml = mapper.writeValueAsString(new Jurisdiction());
        assertEquals("<Jurisdiction name=\"Foo\" value=\"13\"/>", xml);
    }

    public void testAttributeAndElement() throws IOException
    {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.