Package com.sun.jersey.api.json

Examples of com.sun.jersey.api.json.JSONUnmarshaller


public class EmptyJSONElementTest extends TestCase {

    public void testOnlyEmptyElement() throws Exception {
       
        final JSONJAXBContext ctx = new JSONJAXBContext(JSONConfiguration.mapped().rootUnwrapping(false).build(), EmptyElementBean.class);
        final JSONUnmarshaller ju = ctx.createJSONUnmarshaller();

        EmptyElementBean one = ju.unmarshalFromJSON(new StringReader("{\"emptyElementBean\":{}}"), EmptyElementBean.class);
        EmptyElementBean two = ju.unmarshalFromJSON(new StringReader("{\"emptyElementBean\":null}"), EmptyElementBean.class);

        assertEquals(one, two);
    }
View Full Code Here


    }

    public void testEmptyElementAsAContainee() throws Exception {

        final JSONJAXBContext ctx = new JSONJAXBContext(JSONConfiguration.mapped().rootUnwrapping(false).build(), EmptyElementBean.class, EmptyElementContainingBean.class);
        final JSONUnmarshaller ju = ctx.createJSONUnmarshaller();

        EmptyElementContainingBean one = JSONTestHelper.createTestInstance(EmptyElementContainingBean.class);
        EmptyElementContainingBean two = ju.unmarshalFromJSON(new StringReader("{\"emptyElementContainingBean\":{\"emptyElementBean\":{},\"c\":\"foo\",\"d\":\"bar\"}}"), EmptyElementContainingBean.class);

        assertEquals(one, two);
    }
View Full Code Here

    }

    public void _testNamespaces(JSONJAXBContext ctx) throws Exception {

        final JSONMarshaller jm =  ctx.createJSONMarshaller();
        final JSONUnmarshaller ju = ctx.createJSONUnmarshaller();
        final StringWriter sw = new StringWriter();

        final MyResponse one = JSONTestHelper.createTestInstance(MyResponse.class);

        jm.marshallToJSON(one, sw);

        System.out.println(String.format("%s", sw));

        MyResponse two;
        two =  ju.unmarshalFromJSON(new StringReader(sw.toString()), MyResponse.class);

        assertEquals(one, two);
    }
View Full Code Here

    }
   
    public synchronized void allBeansTest(JSONJAXBContext context, Collection<Object> beans) throws Exception {

        JSONMarshaller marshaller = context.createJSONMarshaller();
        JSONUnmarshaller unmarshaller = context.createJSONUnmarshaller();

        for (Object originalBean : beans) {
            printAsXml(originalBean);

            StringWriter sWriter = new StringWriter();
            marshaller.marshallToJSON(originalBean, sWriter);

            System.out.println(sWriter.toString());
            assertEquals(originalBean, unmarshaller.unmarshalFromJSON(new StringReader(sWriter.toString()), originalBean.getClass()));
        }
    }
View Full Code Here

TOP

Related Classes of com.sun.jersey.api.json.JSONUnmarshaller

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.