Examples of JSONMarshaller


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

    @Override
    protected void writeTo(Object t, MediaType mediaType, Charset c,
            Marshaller m, OutputStream entityStream)
            throws JAXBException {
        JSONMarshaller jsonMarshaller = JSONJAXBContext.getJSONMarshaller(m);
        if(isFormattedOutput())
            jsonMarshaller.setProperty(JSONMarshaller.FORMATTED, true);
        jsonMarshaller.marshallToJSON(t, new OutputStreamWriter(entityStream, c));
    }
View Full Code Here

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

public class AnotherArrayTest extends TestCase {

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

        AnotherArrayTestBean one = new AnotherArrayTestBean();
        Cat c1 = new Cat("Foo", "Kitty");
        one.addCat(c1);
        Cat c2 = new Cat("Bar", "Puss");
        one.addCat(c2);
       
        one.setProp("testProp");
       
        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

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

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};
        one.number = 3;
       
        jm.marshallToJSON(one, sw);
        String jsonResult = sw.toString();
        System.out.println(jsonResult);
       
        String expectedResult = "{\"intArray\":[1].\"integerArray\":[2],\"number\":3}";
        assertEquals(expectedResult, jsonResult);
View Full Code Here

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

    }

    private void tryConfiguration(JSONConfiguration configuration) throws Exception {

        final JSONJAXBContext ctx = new JSONJAXBContext(configuration, NamespaceBean.class);
        final JSONMarshaller jm = ctx.createJSONMarshaller();
        final JSONUnmarshaller ju = ctx.createJSONUnmarshaller();


        NamespaceBean beanTwo;

        final StringWriter sw = new StringWriter();

        jm.marshallToJSON(one, sw);

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

        beanTwo = ju.unmarshalFromJSON(new StringReader(sw.toString()), NamespaceBean.class);
View Full Code Here

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

    }

    public void _testException(final String value) throws Exception {
        final JSONJAXBContext ctx = new JSONJAXBContext(
                JSONConfiguration.mapped().build(), Bean.class);
        final JSONMarshaller jm = ctx.createJSONMarshaller();
        final StringWriter sw = new StringWriter();
        final Writer w = new FilterWriter(sw) {
            @Override
            public void write(String str) throws IOException {
                if (str.contains(value))
                    throw new IOException();
                super.write(str);
            }
        };

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

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

        _testNamespaces(ctx);
    }

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

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

        allBeansTest(new JSONJAXBContext(classes, props), beans);
    }
   
    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

Examples of com.sun.jersey.json.impl.JSONMarshaller

    @Override
    protected void writeTo(Object t, MediaType mediaType, Charset c,
            Marshaller m, OutputStream entityStream)
            throws JAXBException, IOException {
        if (m instanceof JSONMarshaller) {
            JSONMarshaller jm = (JSONMarshaller)m;
            jm.setJsonEnabled(true);
            jm.marshal(t,
                    new OutputStreamWriter(entityStream, c));
        } else {
            m.marshal(t, JsonXmlStreamWriter.createWriter(
                    new OutputStreamWriter(entityStream, c), true));
        }
View Full Code Here

Examples of com.sun.jersey.json.impl.JSONMarshaller

     * @return marshaller instance with JSON capabilities
     * @throws javax.xml.bind.JAXBException
     */
    @Override
    public Marshaller createMarshaller() throws JAXBException {
        return new JSONMarshaller(jaxbContext, getJSONConfiguration());
    }
View Full Code Here

Examples of org.springframework.boot.configurationprocessor.metadata.JsonMarshaller

        FileObject resource = this.processingEnv.getFiler().createResource(
            StandardLocation.CLASS_OUTPUT, "",
            "META-INF/spring-configuration-metadata.json");
        OutputStream outputStream = resource.openOutputStream();
        try {
          new JsonMarshaller().write(metadata, outputStream);
        }
        finally {
          outputStream.close();
        }
      }
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.