Examples of JacksonXMLProvider


Examples of com.fasterxml.jackson.jaxrs.xml.JacksonXMLProvider

        public int a = 3;
    }
   
    public void testRootType() throws Exception
    {
        JacksonXMLProvider prov = new JacksonXMLProvider();
        TypeReference<?> ref = new TypeReference<List<Bean>>(){};
        ArrayList<Bean> list = new ArrayList<Bean>();
        list.add(new Bean());
        list.add(new Bean());
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        MediaType mt = MediaType.APPLICATION_JSON_TYPE;
        prov.writeTo(list, List.class, ref.getType(), new Annotation[0], mt, null, out);

        String xml = out.toString("UTF-8");
        /* 09-Oct-2013, tatu: With 2.2, this produced "unwrapped" output; but
         *   with 2.3 it should use same defaults as XML module. So 'wrappers'
         *   are used for Collections, unless explicitly disabled.
View Full Code Here

Examples of com.fasterxml.jackson.jaxrs.xml.JacksonXMLProvider

    /**********************************************************
     */
   
    public void testDefaultUntouchables() throws Exception
    {
        JacksonXMLProvider prov = new JacksonXMLProvider();
        // By default, no reason to exclude, say, this test class...
        assertTrue(prov.isReadable(getClass(), getClass(), null, null));
        assertTrue(prov.isWriteable(getClass(), getClass(), null, null));

        // but some types should be ignored (set of ignorable may change over time tho!)
        assertFalse(prov.isWriteable(StreamingOutput.class, StreamingOutput.class, null, null));

        // and then on-the-fence things (see [Issue-1])
        assertFalse(prov.isReadable(String.class, getClass(), null, null));
        assertFalse(prov.isReadable(byte[].class, getClass(), null, null));
    }
View Full Code Here

Examples of com.fasterxml.jackson.jaxrs.xml.JacksonXMLProvider

        assertFalse(prov.isReadable(byte[].class, getClass(), null, null));
    }

    public void testCustomUntouchables() throws Exception
    {
        JacksonXMLProvider prov = new JacksonXMLProvider();       
        // can mark this as ignorable...
        prov.addUntouchable(getClass());
        // and then it shouldn't be processable
        assertFalse(prov.isReadable(getClass(), getClass(), null, null));
        assertFalse(prov.isWriteable(getClass(), getClass(), null, null));

        // Same for interfaces, like:
        prov.addUntouchable(Collection.class);
        assertFalse(prov.isReadable(ArrayList.class, ArrayList.class, null, null));
        assertFalse(prov.isWriteable(HashSet.class, HashSet.class, null, null));
    }
View Full Code Here

Examples of com.fasterxml.jackson.jaxrs.xml.JacksonXMLProvider

public class TestXMLVersions extends JaxrsTestBase
{
    public void testMapperVersions()
    {
        assertVersion(new JacksonXMLProvider());
    }
View Full Code Here

Examples of com.fasterxml.jackson.jaxrs.xml.JacksonXMLProvider

    }

    protected static abstract class XMLApplicationWithJackson extends XMLApplication
    {
        public XMLApplicationWithJackson(Object resource) {
            super(new JacksonXMLProvider(), resource);
        }
View Full Code Here

Examples of com.fasterxml.jackson.jaxrs.xml.JacksonXMLProvider

     */

    // [Issue-2], serialization
    public void testWriteConfigs() throws Exception
    {
        JacksonXMLProvider prov = new JacksonXMLProvider();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        Bean bean = new Bean();
        Method m = getClass().getDeclaredMethod("writeConfig");
        JacksonFeatures feats = m.getAnnotation(JacksonFeatures.class);
        assertNotNull(feats); // just a sanity check

        /* 09-Oct-2013, tatu: As of 2.3, XML backend does NOT add extra wrapping
         *   any more: it is only added to JSON where it is needed; but not
         *   to XML which always basically uses wrapping.
         */
        try {
            prov.writeTo(bean, bean.getClass(), bean.getClass(), new Annotation[] { feats },
                    MediaType.APPLICATION_JSON_TYPE, null, out);
        } catch (Exception e) {
            throw unwrap(e);
        }

        //
        assertEquals("<Bean><a>3</a></Bean>", out.toString("UTF-8"));

        // but without, not:
        out.reset();
        prov.writeTo(bean, bean.getClass(), bean.getClass(), new Annotation[] { },
                MediaType.APPLICATION_JSON_TYPE, null, out);
        assertEquals("<Bean><a>3</a></Bean>", out.toString("UTF-8"));
    }
View Full Code Here

Examples of com.fasterxml.jackson.jaxrs.xml.JacksonXMLProvider

        assertEquals("<Bean><a>3</a></Bean>", out.toString("UTF-8"));
    }
   
    public void testWriteConfigsViaBundle() throws Exception
    {
        JacksonXMLProvider prov = new JacksonXMLProvider();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        Bean bean = new Bean();
        Method m = getClass().getDeclaredMethod("writeConfig2");
        // should still enable root-wrapping
        prov.writeTo(bean, bean.getClass(), bean.getClass(), m.getAnnotations(),
                MediaType.APPLICATION_JSON_TYPE, null, out);
        // as per above, no extra wrapping for XML, in 2.3:
        assertEquals("<Bean><a>3</a></Bean>", out.toString("UTF-8"));
    }
View Full Code Here

Examples of com.fasterxml.jackson.jaxrs.xml.JacksonXMLProvider

    }
   
    // [Issue-2], deserialization
    public void testReadConfigs() throws Exception
    {
        JacksonXMLProvider prov = new JacksonXMLProvider();
        Method m = getClass().getDeclaredMethod("readConfig");
        JacksonFeatures feats = m.getAnnotation(JacksonFeatures.class);
        assertNotNull(feats); // just a sanity check

        // ok: here let's verify that we can disable exception throwing unrecognized things
        @SuppressWarnings("unchecked")
        Class<Object> raw = (Class<Object>)(Class<?>)Bean.class;
        Object ob = prov.readFrom(raw, raw,
                new Annotation[] { feats },
                MediaType.APPLICATION_JSON_TYPE, null,
                new ByteArrayInputStream("<Bean><foobar>3</foobar></Bean>".getBytes("UTF-8")));
        assertNotNull(ob);

        // but without setting, get the exception
        try {
            prov.readFrom(raw, raw,
                    new Annotation[] { },
                    MediaType.APPLICATION_JSON_TYPE, null,
                    new ByteArrayInputStream("<Bean><foobar>3</foobar></Bean>".getBytes("UTF-8")));
            fail("Should have caught an exception");
        } catch (JsonMappingException e) {
View Full Code Here

Examples of com.fasterxml.jackson.jaxrs.xml.JacksonXMLProvider

    /**********************************************************
     */
   
    public void testDefaultUntouchables() throws Exception
    {
        JacksonXMLProvider prov = new JacksonXMLProvider();
        // By default, no reason to exclude, say, this test class...
        assertTrue(prov.isReadable(getClass(), getClass(), null, null));
        assertTrue(prov.isWriteable(getClass(), getClass(), null, null));

        // but some types should be ignored (set of ignorable may change over time tho!)
        assertFalse(prov.isWriteable(StreamingOutput.class, StreamingOutput.class, null, null));

        // and then on-the-fence things (see [Issue-1])
        assertFalse(prov.isReadable(String.class, getClass(), null, null));
        assertFalse(prov.isReadable(byte[].class, getClass(), null, null));
    }
View Full Code Here

Examples of com.fasterxml.jackson.jaxrs.xml.JacksonXMLProvider

        assertFalse(prov.isReadable(byte[].class, getClass(), null, null));
    }

    public void testCustomUntouchables() throws Exception
    {
        JacksonXMLProvider prov = new JacksonXMLProvider();       
        // can mark this as ignorable...
        prov.addUntouchable(getClass());
        // and then it shouldn't be processable
        assertFalse(prov.isReadable(getClass(), getClass(), null, null));
        assertFalse(prov.isWriteable(getClass(), getClass(), null, null));

        // Same for interfaces, like:
        prov.addUntouchable(Collection.class);
        assertFalse(prov.isReadable(ArrayList.class, ArrayList.class, null, null));
        assertFalse(prov.isWriteable(HashSet.class, HashSet.class, null, null));
    }
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.