Package com.sun.jersey.api.json

Examples of com.sun.jersey.api.json.JSONMarshaller.marshallToJSON()


        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


                super.write(str);
            }
        };

        Bean b = new Bean("A", "B", "C");
        jm.marshallToJSON(b, w);
    }
}
View Full Code Here

        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;
View Full Code Here

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

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

        jm.marshallToJSON(one, sw);
        String jsonResult = sw.toString();

        assertEquals("{\"weight\":[\"1kg\",\"2kg\"],\"color\":[\"red\"],\"name\":\"bumper\"}", jsonResult);
    }
}
View Full Code Here

            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) {
View Full Code Here

        final JAXBElement<AnotherArrayTestBean> unmarshal = unmarshaller.unmarshal(new StreamSource(new StringReader(sw1
                .toString())), AnotherArrayTestBean.class);

        marshaller.marshal(unmarshal, System.out);

        jm.marshallToJSON(one, sw);
        String jsonResult = sw.toString();
        System.out.println(jsonResult);

        String excpectedResult = "{\"cats\":[{\"name\":\"Foo\",\"nickName\":\"Kitty\"},{\"name\":\"Bar\",\"nickName\":\"Puss\"}],\"prop\":\"testProp\"}";
        assertEquals(excpectedResult, jsonResult);
View Full Code Here

        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);
View Full Code Here

        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);
View Full Code Here

            throws JAXBException {

        JSONMarshaller jsonMarshaller = JSONJAXBContext.getJSONMarshaller(m, getStoredJAXBContext(t.getDeclaredType()));
        if(isFormattedOutput())
            jsonMarshaller.setProperty(JSONMarshaller.FORMATTED, true);
        jsonMarshaller.marshallToJSON(t, new OutputStreamWriter(entityStream, c));
    }
}
View Full Code Here

        one.intArray = new int[] {1};
        one.integerArray = new Integer[] {2};
        one.integerList = new ArrayList<Integer>() {{ add(4); }};
        one.number = 3;
       
        jm.marshallToJSON(one, sw);
        String jsonResult = sw.toString();
        System.out.println(jsonResult);
       
        String expectedResult = "{\"intArray\":[1],\"integerArray\":[2],\"integerList\":[4],\"number\":3}";
        assertEquals(expectedResult, jsonResult);
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.