Package com.sun.jersey.api.json

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


        tryConfigurationWithStringInput(JSONConfiguration.mapped().rootUnwrapping(true).xml2JsonNs(ns2json).build(), "{\"nullString\":null}");
    }

    private void tryConfigurationWithStringInput(JSONConfiguration configuration, String inputJSON) throws Exception {
        final JSONJAXBContext ctx = new JSONJAXBContext(configuration, NullStringBean.class);
        final JSONUnmarshaller ju = ctx.createJSONUnmarshaller();

        NullStringBean two = ju.unmarshalFromJSON(new StringReader(inputJSON), NullStringBean.class);

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


    private void tryWithConfiguration(JSONConfiguration configuration) throws Exception {

        final JSONJAXBContext ctx = new JSONJAXBContext(configuration, NullStringBean.class);
        final JSONMarshaller jm = ctx.createJSONMarshaller();
        final JSONUnmarshaller ju = ctx.createJSONUnmarshaller();
        StringWriter sw = new StringWriter();
        jm.marshallToJSON(one, sw);
        System.out.println(String.format("Marshalled: %s", sw));

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

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

    public void testRoundtripWithPrefixAdded() throws Exception {

        final JSONJAXBContext ctx = new JSONJAXBContext(JSONConfiguration.natural().usePrefixesAtNaturalAttributes().build(), SimpleBeanWithAttributes.class);
        final JSONMarshaller jm = ctx.createJSONMarshaller();
        final JSONUnmarshaller ju = ctx.createJSONUnmarshaller();
        final StringWriter sw = new StringWriter();

        final SimpleBeanWithAttributes one = JSONTestHelper.createTestInstance(SimpleBeanWithAttributes.class);
        jm.marshallToJSON(one, sw);
        System.out.println(sw.toString());
       
        SimpleBeanWithAttributes unmarshalledOne = ju.unmarshalFromJSON(new StringReader(sw.toString()), SimpleBeanWithAttributes.class);

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

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\":{\"nullOnly\":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);

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

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

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

            final Class<?>[] classesToBeBound = {beanClass};
            JSONJAXBContext context = properties.isEmpty() ?
                    new JSONJAXBContext(configuration, classesToBeBound) : new JSONJAXBContext(classesToBeBound, properties);

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

            printAsXml(originalBean);

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

            System.out.println(sWriter.toString());
            final Object actual = unmarshaller.unmarshalFromJSON(new StringReader(sWriter.toString()), beanClass);

            if (useDefaultConfiguration) {
                // let know the bean that the old approach (instance with empty properties -> 'null') is being tested so it should
                // handle the equals method a little bit different
                try {
View Full Code Here

    private void tryListWithConfiguration(JSONConfiguration configuration) throws Exception {

        final JSONJAXBContext ctx = new JSONJAXBContext(configuration, AnimalList.class, Animal.class, Dog.class, Cat.class);
        final JSONMarshaller jm = ctx.createJSONMarshaller();
        final JSONUnmarshaller ju = ctx.createJSONUnmarshaller();
        final StringWriter sw = new StringWriter();

        AnimalList two;
        jm.marshallToJSON(one, sw);

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

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

        assertEquals(one, two);
        for (int i = 0; i < one.animals.size(); i++) {
            assertEquals(one.animals.get(i).getClass(), two.animals.get(i).getClass());
        }
View Full Code Here

    private void tryIndividualsWithConfiguration(JSONConfiguration configuration) throws Exception {

        final JSONJAXBContext ctx = new JSONJAXBContext(configuration, AnimalList.class, Animal.class, Dog.class, Cat.class);
        final JSONMarshaller jm = ctx.createJSONMarshaller();
        final JSONUnmarshaller ju = ctx.createJSONUnmarshaller();


        Animal animalTwo;

        for (int i = 0; i < one.animals.size(); i++) {

            final StringWriter sw = new StringWriter();
            Animal animalOne = one.animals.get(i);

            jm.marshallToJSON(animalOne, sw);

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

            animalTwo = ju.unmarshalFromJSON(new StringReader(sw.toString()), Animal.class);

            assertEquals(animalOne, animalTwo);
            System.out.println(String.format("class one = %s; class two = %s", animalOne.getClass(), animalTwo.getClass()));
            assertEquals(animalOne.getClass(), animalTwo.getClass());
        }
View Full Code Here

    public void testRegisterMessage() throws Exception {

        final JSONJAXBContext ctx = new JSONJAXBContext(JSONConfiguration.mapped().rootUnwrapping(false).attributeAsElement("agentUID", "requestTime").nonStrings("requestTime").build(), RegisterMessage.class);
        final JSONMarshaller jm = ctx.createJSONMarshaller();
        final JSONUnmarshaller ju = ctx.createJSONUnmarshaller();
        final StringWriter sw = new StringWriter();

        final RegisterMessage one = JSONTestHelper.createTestInstance(RegisterMessage.class);
        RegisterMessage two;
        jm.marshallToJSON(one, sw);

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

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

        assertEquals(one, two);
    }
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.