Examples of JacksonXMLProvider


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

    private final static String GROUP_ID = "com.fasterxml.jackson.jaxrs";
    private final static String ARTIFACT_ID = "jackson-jaxrs-xml-provider";
   
    public void testMapperVersions()
    {
        assertVersion(new JacksonXMLProvider());
    }
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

        // 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();
        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);
        assertEquals("<Bean><Bean><a>3</a></Bean></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

     */

    // [JACKSON-578]
    public void testViews() throws Exception
    {
        JacksonXMLProvider prov = new JacksonXMLProvider();
        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

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

        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

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

            // Show exception messages in responses
            new OTPExceptionMapper(),
            // Enable Jackson JSON response serialization
            new JacksonJsonProvider(),
            // Enable Jackson XML response serialization
            new JacksonXMLProvider(),
            // Serialize POJOs (unannotated) JSON using Jackson
            new JSONObjectMapperProvider(),
            // Allow injecting the OTP server object into Jersey resource classes
            server.makeBinder()
        );
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.