Package com.fasterxml.jackson.jaxrs.xml

Examples of com.fasterxml.jackson.jaxrs.xml.JacksonXMLProvider.writeTo()


        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


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

View Full Code Here

        //
        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"));
    }
   
    public void testWriteConfigsViaBundle() throws Exception
View Full Code Here

        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

        Method m = getClass().getDeclaredMethod("writeConfig");
        JacksonFeatures feats = m.getAnnotation(JacksonFeatures.class);
        assertNotNull(feats); // just a sanity check

        // when (extra) wrapping enabled, we get:
        prov.writeTo(bean, bean.getClass(), bean.getClass(), new Annotation[] { feats },
                MediaType.APPLICATION_JSON_TYPE, null, out);
        assertEquals("<Bean><Bean><a>3</a></Bean></Bean>", out.toString("UTF-8"));

        // but without, not:
        out.reset();
View Full Code Here

                MediaType.APPLICATION_JSON_TYPE, null, out);
        assertEquals("<Bean><Bean><a>3</a></Bean></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"));
    }

    public void testWriteConfigsViaBundle() throws Exception
View Full Code Here

        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);
        assertEquals("<Bean><Bean><a>3</a></Bean></Bean>", out.toString("UTF-8"));
    }
   
    // [Issue-2], deserialization
View Full Code Here

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        Bean bean = new Bean();
        Method m = getClass().getDeclaredMethod("bogus");
        JsonView view = m.getAnnotation(JsonView.class);
        assertNotNull(view); // just a sanity check
        prov.writeTo(bean, bean.getClass(), bean.getClass(), new Annotation[] { view },
                MediaType.APPLICATION_JSON_TYPE, null, out);
        assertEquals("<Bean><value1>1</value1></Bean>", out.toString("UTF-8"));
    }
}
View Full Code Here

        Bean bean = new Bean();
        ArrayList<Bean> list = new ArrayList<Bean>();
        list.add(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");
        assertEquals("<List><bean><a>3</a></bean></List>", xml);
    }
}
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.