Package com.fasterxml.jackson.dataformat.xml

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


    // let's actually reuse XmlMapper to make things bit faster
    @Override
    public void setUp() throws Exception {
        super.setUp();
        _xmlMapper = new XmlMapper();
        _xmlMapper.configure(SerializationFeature.INDENT_OUTPUT, true);
    }
View Full Code Here


    /**********************************************************
     */
   
    public void testXml10Declaration() throws Exception
    {
        XmlMapper mapper = new XmlMapper();
        mapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);
        String xml = mapper.writeValueAsString(new StringBean("123"));
        assertEquals(xml, "<?xml version='1.0' encoding='UTF-8'?><StringBean><text>123</text></StringBean>");
    }
View Full Code Here

        assertEquals(xml, "<?xml version='1.0' encoding='UTF-8'?><StringBean><text>123</text></StringBean>");
    }

    public void testXml11Declaration() throws Exception
    {
        XmlMapper mapper = new XmlMapper();
        mapper.configure(ToXmlGenerator.Feature.WRITE_XML_1_1, true);
        String xml = mapper.writeValueAsString(new StringBean("abcd"));
        assertEquals(xml, "<?xml version='1.1' encoding='UTF-8'?><StringBean><text>abcd</text></StringBean>");
    }
View Full Code Here

    // let's actually reuse XmlMapper to make things bit faster
    @Override
    public void setUp() throws Exception {
        super.setUp();
        _xmlMapper = new XmlMapper();
    }
View Full Code Here

        assertEquals(origXml, _writeXml(f2, true));
    }

    public void testMapper() throws IOException
    {
        XmlMapper mapper = new XmlMapper();
        final String EXP = "<MyPojo><x>2</x><y>3</y></MyPojo>";
        final MyPojo p = new MyPojo(2, 3);
        assertEquals(EXP, mapper.writeValueAsString(p));

        byte[] bytes = jdkSerialize(mapper);
        XmlMapper mapper2 = jdkDeserialize(bytes);
        assertEquals(EXP, mapper2.writeValueAsString(p));
        MyPojo p2 = mapper2.readValue(EXP, MyPojo.class);
        assertEquals(p.x, p2.x);
        assertEquals(p.y, p2.y);
    }
View Full Code Here

        } catch (JsonProcessingException e) {
            verifyException(e, "Unrecognized");
        }
        JacksonXmlModule module = new JacksonXmlModule();
        module.setXMLTextElementName("value");
        XmlMapper mapper = new XmlMapper(module);
        JAXBStyle pojo = mapper.readValue(XML, JAXBStyle.class);
        assertEquals("foo", pojo.value);
    }
View Full Code Here

    // [Issue#66], implicit property from "XmlText"
    public void testIssue66() throws Exception
    {
        JacksonXmlModule module = new JacksonXmlModule();
        module.setDefaultUseWrapper(false);
        XmlMapper mapper = new XmlMapper(module);
        final String XML = "<Issue66Bean id=\"id\">text</Issue66Bean>";

        // let's start with deserialization
        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);
    }
View Full Code Here

    }

    // [Issue#72]
    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);
        assertEquals("bar", result.b.textValue);
    }
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;
       
        if (TestEnum.class != ob.getClass()) {
View Full Code Here

    /**********************************************************************
     */

    public void testIssue27() throws Exception
    {
        XmlMapper mapper = new XmlMapper();

        Bean bean = new Bean();
        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

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.