Package com.fasterxml.jackson.dataformat.xml

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


    public void testDefaultWrappingWithEmptyLists() throws Exception
    {
        // by default, should be using wrapping, so:
        XmlMapper mapper = new XmlMapper();
        String json = "<DefaultList><value><value></value></value></DefaultList>";
        DefaultList output = mapper.readValue(json, DefaultList.class);
        assertNotNull(output.value);
        assertEquals(1, output.value.length);

        // but without, should work as well
        JacksonXmlModule module = new JacksonXmlModule();
View Full Code Here


        // but without, should work as well
        JacksonXmlModule module = new JacksonXmlModule();
        module.setDefaultUseWrapper(false);
        mapper = new XmlMapper(module);
        json = "<DefaultList><value></value></DefaultList>";
        output = mapper.readValue(json, DefaultList.class);
        assertNotNull(output.value);
        assertEquals(1, output.value.length);
    }

    // // [Issue#64]
View Full Code Here

    // // [Issue#64]
    public void testOptionalsWithMissingType() throws Exception
    {
        XmlMapper mapper = new XmlMapper();
//        Optionals ob = MAPPER.readValue("<MultiOptional><optional type='work'>123-456-7890</optional></MultiOptional>",
        Optionals ob = mapper.readValue("<MultiOptional><optional>123-456-7890</optional></MultiOptional>",
                Optionals.class);
        assertNotNull(ob);
        assertNotNull(ob.optional);
        assertEquals(1, ob.optional.size());
View Full Code Here

        xmlMapper.registerModule(m);

        Item value = new Item("itemName", new Foo("fooName"));
        String xml = xmlMapper.writeValueAsString(value);
       
        Item result = xmlMapper.readValue(xml, Item.class);
        assertNotNull(result);
        assertEquals("itemName", result.name);
        assertNotNull(result.obj);
        assertEquals("fooName", result.obj.name);
    }
View Full Code Here

     * [Issue#60]: should be able to detect "no content", ideally.
     */
    public void testNoContent() throws Exception
    {
        XmlMapper mapper = new XmlMapper();
        assertNull(mapper.readValue("", EmptyBean.class));
    }
}
View Full Code Here

    mapper.setSerializationInclusion(Include.NON_NULL);

    final String xml = mapper.writeValueAsString(before);
    assertEquals(source, xml);

    final Issue86 after = mapper.readValue(xml, Issue86.class);
    assertEquals(before, after);
  }
}
View Full Code Here

        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

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

    // [Issue#66], implicit property from "XmlText"
    public void testIssue66() throws Exception
View Full Code Here

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

        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

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.