Package com.fasterxml.jackson.dataformat.xml

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


            xmlFactory = InitialContext.doLookup(xmlFactoryLookup);
            xmlMapper = (XmlMapper) xmlFactory.getCodec();
        } else {
            initXmlModule();
            xmlFactory = new XmlFactory();
            xmlMapper = xmlModule == null ? new XmlMapper(xmlFactory) : new XmlMapper(xmlFactory, xmlModule);
            xmlFactory.setCodec(xmlMapper);
        }
    }
View Full Code Here


                    } else {
                        throw SupportMessages.MESSAGES.invalidReaderWriterProperty(null, (String) defaultUseWrapper, "defaultUseWrapper");
                    }
                }

                final XmlMapper xmlMapper = xmlModule == null ? new XmlMapper(xmlFactory) : new XmlMapper(xmlFactory, xmlModule);
                xmlFactory.setCodec(xmlMapper);
            }
        }
        return xmlFactory;
    }
View Full Code Here

    public void setUp() throws Exception
    {
        super.setUp();
        JacksonXmlModule module = new JacksonXmlModule();
        module.setDefaultUseWrapper(false);
        _xmlMapper = new XmlMapper(module);
        _xmlMapper.setPropertyNamingStrategy(new PropertyNamingStrategy.PascalCaseStrategy());
        _xmlMapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
    }
View Full Code Here

   
        void setValues(final List<Value> values) { this.values = values; }
    }

    public void testCollection() throws Exception {
        final Values values = new XmlMapper().readValue("<values type=\"array\">" +
                                                        "  <value><v>c</v></value>" +
                                                        "  <value><v>d</v></value>" +
                                                        "</values>",
                                                        Values.class);
        assertEquals(2, values.getValues().size(), 2);
View Full Code Here

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

    public void testWrappedLists() throws Exception
    {
        XmlMapper mapper = new XmlMapper();
        WrappedList list = new WrappedList();
        list.value = new Value[] { new Value("a"), new Value("b") };

        // First, serialize:
       
        String json = mapper.writeValueAsString(list);
//      withJAXB(list);
        assertEquals("<list><WRAP><value><v>a</v></value><value><v>b</v></value></WRAP></list>", json);

        // then deserialize back
        WrappedList output = mapper.readValue(json, WrappedList.class);
        assertNotNull(output);
        assertNotNull(output.value);
        assertEquals(2, output.value.length);
    }
View Full Code Here

        assertEquals(2, output.value.length);
    }
   
    public void testUnwrappedLists() throws Exception
    {
        XmlMapper mapper = new XmlMapper();

        UnwrappedList list = new UnwrappedList();
        list.value = new Value[] { new Value("c"), new Value("d") };
        String json = mapper.writeValueAsString(list);
       
//        System.out.println("Unwrapped == "+json);
//        withJAXB(list);
        assertEquals("<list><value><v>c</v></value><value><v>d</v></value></list>", json);

        // then deserialize back
        UnwrappedList output = mapper.readValue(json, UnwrappedList.class);
        assertNotNull(output);
        assertNotNull(output.value);
        assertEquals(2, output.value.length);
   
    }
View Full Code Here

     * Test to verify that default wrapping setting is used
     */
    public void testDefaultWrapping() throws Exception
    {
        // by default, should be using wrapping, so:
        XmlMapper mapper = new XmlMapper();
        DefaultList input = new DefaultList();
        input.value = new Value[] { new Value("a"), new Value("b") };
        String json = mapper.writeValueAsString(input);
        assertEquals("<DefaultList><value><value><v>a</v></value><value><v>b</v></value></value></DefaultList>", json);
        DefaultList output = mapper.readValue(json, DefaultList.class);
        assertNotNull(output.value);
        assertEquals(2, output.value.length);

        // but can be changed not to use wrapping by default
        JacksonXmlModule module = new JacksonXmlModule();
        module.setDefaultUseWrapper(false);
        mapper = new XmlMapper(module);
        json = mapper.writeValueAsString(input);
        assertEquals("<DefaultList><value><v>a</v></value><value><v>b</v></value></DefaultList>", json);
        output = mapper.readValue(json, DefaultList.class);
        assertNotNull(output.value);
        assertEquals(2, output.value.length);
    }
View Full Code Here

    }

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

    // Test for ensuring that we can use ".withRootName()" to override
    // default name AND annotation
    public void testRenamedRootItem() throws Exception
    {
        XmlMapper xmlMapper = new XmlMapper();
        String xml = xmlMapper
                .writer()
                .withRootName("Shazam")
                .writeValueAsString(new SampleResource(123, "Foo", "Barfy!"))
                .trim();
        xml = removeSjsxpNamespace(xml);
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.