Examples of JSONUnmarshaller


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

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

    }

    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

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

    }

    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

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

    }
   
    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.JSONUnmarshaller

            Unmarshaller u, InputStream entityStream)
            throws JAXBException, IOException {
        final Charset c = getCharset(mediaType);
        if (type.isAnnotationPresent(XmlRootElement.class)) {
            if (u instanceof JSONUnmarshaller) {
                JSONUnmarshaller ju = (JSONUnmarshaller)u;
                ju.setJsonEnabled(true);
                JAXBElement jaxbElem = (JAXBElement)ju.
                        unmarshal(new InputStreamReader(entityStream, c),
                        type);
                return jaxbElem.getValue();
            } else {
                return u.unmarshal(
                        new JsonXmlStreamReader(
                            new InputStreamReader(entityStream, c),
                            JSONHelper.getRootElementName(type)));
            }
        } else {
            if (u instanceof JSONUnmarshaller) {
                // TODO what about the charset ?
                JSONUnmarshaller ju = (JSONUnmarshaller)u;
                ju.setJsonEnabled(true);
                return ju.unmarshal(new StreamSource(entityStream), type).getValue();
            } else {
                return u.unmarshal(
                        new JsonXmlStreamReader(
                            new InputStreamReader(entityStream, c),
                            JSONHelper.getRootElementName(type)), type).getValue();
View Full Code Here

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

     * @return unmarshaller instance with JSON capabilities
     * @throws javax.xml.bind.JAXBException
     */
    @Override
    public Unmarshaller createUnmarshaller() throws JAXBException {
        return new JSONUnmarshaller(jaxbContext, getJSONConfiguration());
    }
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.