Package com.sun.jersey.api.json

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


*/
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


        assertEquals(one, two);
    }

    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

* @author Jakub Podlesak (jakub.podlesak at oracle.com)
*/
public class NamespaceSupportIssue272Test extends TestCase {

    public void testNaturalNotation() throws Exception {
        _testNamespaces(new JSONJAXBContext(JSONConfiguration.natural().build(), MyError.class, MyMessage.class, MyResponse.class));
    }
View Full Code Here

    }

    public void testMappedNotation() throws Exception {
        Map<String, String> jsonXml2JsonNs = new HashMap<String, String>();
        jsonXml2JsonNs.put("http://test.jaxb.com", "tjc");
        final JSONJAXBContext ctx = new JSONJAXBContext(JSONConfiguration.mapped().xml2JsonNs(jsonXml2JsonNs).build(), MyError.class, MyMessage.class, MyResponse.class);
        _testNamespaces(ctx);
    }
View Full Code Here

*/
public class FakeArrayTest extends TestCase {

    public void testSimpleXmlTypeBean() throws Exception {
       
        final JSONJAXBContext ctx = new JSONJAXBContext(JSONConfiguration.mapped().arrays("color").build(), FakeArrayBean.class);
        final JSONMarshaller jm = ctx.createJSONMarshaller();
        final StringWriter sw = new StringWriter();

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

        jm.marshallToJSON(one, sw);
View Full Code Here

                configuration = builder.build();
            }

            final Class<? extends Object> beanClass = originalBean.getClass();
            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);
View Full Code Here

        tryIndividualsWithConfiguration(JSONConfiguration.mapped().rootUnwrapping(false).build());
    }

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

*/
public class IntArrayTest extends TestCase {

    public void testBracketsAreNotMissingAndNumbersAreNotQuoted() throws Exception {
       
        final JSONJAXBContext ctx = new JSONJAXBContext(JSONConfiguration.natural().build(), IntArray.class);
        final JSONMarshaller jm = ctx.createJSONMarshaller();
        final StringWriter sw = new StringWriter();

        IntArray one = new IntArray();
        one.intArray = new int[] {1};
        one.integerArray = new Integer[] {2};
View Full Code Here

*/
public class RegisterMessageTest extends TestCase {

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

TOP

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

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.