Package org.codehaus.jackson

Examples of org.codehaus.jackson.JsonGenerator


        super(testName);
    }

    public void testWrapppingNull() throws Exception {
        StringWriter sw = new StringWriter();
        JsonGenerator g = (new JsonFactory()).createJsonGenerator(sw);
        JsonGenerator awg = JacksonArrayWrapperGenerator.createArrayWrapperGenerator(g);
        awg.writeNull();
        awg.close();
        assertEquals("[]",sw.toString());
    }
View Full Code Here


        assertEquals("[]",sw.toString());
    }

    public void testWrapppingDoubleNull() throws Exception {
        StringWriter sw = new StringWriter();
        JsonGenerator g = (new JsonFactory()).createJsonGenerator(sw);
        JsonGenerator awg = JacksonArrayWrapperGenerator.createArrayWrapperGenerator(g);
        awg.writeNull();
        awg.writeNull();
        awg.close();
        assertEquals("[null,null]",sw.toString());
    }
View Full Code Here

        assertEquals("[null,null]",sw.toString());
    }

    public void testWrapppingString() throws Exception {
        StringWriter sw = new StringWriter();
        JsonGenerator g = (new JsonFactory()).createJsonGenerator(sw);
        JsonGenerator awg = JacksonArrayWrapperGenerator.createArrayWrapperGenerator(g);
        awg.writeString("string");
        awg.close();
        assertEquals("[\"string\"]",sw.toString());
    }
View Full Code Here

        assertEquals("[\"string\"]",sw.toString());
    }

    public void testWrapppingNumberAndString() throws Exception {
        StringWriter sw = new StringWriter();
        JsonGenerator g = (new JsonFactory()).createJsonGenerator(sw);
        JsonGenerator awg = JacksonArrayWrapperGenerator.createArrayWrapperGenerator(g);
        awg.writeNumber(2);
        awg.writeString("string");
        awg.close();
        assertEquals("[2,\"string\"]",sw.toString());
    }
View Full Code Here

            jaxbContext = ((JSONJAXBContext) jaxbContext).getOriginalJaxbContext();
        }

        switch (config.getNotation()) {
            case NATURAL:
                final JsonGenerator rawGenerator = new JsonFactory().createJsonGenerator(writer);
                if (config.isHumanReadableFormatting()) {
                    rawGenerator.useDefaultPrettyPrinter();
                }
                final JsonGenerator bodyGenerator = writingList ? JacksonArrayWrapperGenerator.createArrayWrapperGenerator(rawGenerator, config.isRootUnwrapping() ? 0 : 1) : rawGenerator;
                if (config.isRootUnwrapping()) {
                    return new Stax2JacksonWriter(JacksonRootStrippingGenerator.createRootStrippingGenerator(bodyGenerator, writingList ? 2 : 1), config, expectedType, jaxbContext);
                } else {
                    return new Stax2JacksonWriter(bodyGenerator, config, expectedType, jaxbContext);
                    }
View Full Code Here

    public void testMultipleCharactersWithinSimpleTagEvent() throws Exception {
        Map<String, Object> props = new HashMap<String, Object>();

        JsonFactory factory = new JsonFactory();
        Writer osWriter = new OutputStreamWriter(System.out);
        JsonGenerator g;

        g = factory.createJsonGenerator(osWriter);
        final Stax2JacksonWriter s2jWriter = new Stax2JacksonWriter(g, null, null);

        try {
            s2jWriter.writeStartDocument();
            s2jWriter.writeStartElement("simpleTag");
            s2jWriter.writeCharacters("text1\n");
            s2jWriter.writeCharacters("text2\n");
            s2jWriter.writeEndElement();
            s2jWriter.writeEndDocument();
        } catch (XMLStreamException e) {
            fail();
        } finally {
            g.flush();
            System.out.println("");
        }
    }
View Full Code Here

        JAXBContext ctx = JAXBContext.newInstance(classes, props);

        JsonFactory factory = new JsonFactory();
        Writer osWriter = new OutputStreamWriter(System.out);
        JsonGenerator g;

        g = factory.createJsonGenerator(osWriter);

        Marshaller marshaller = ctx.createMarshaller();
        marshaller.marshal(bean, new Stax2JacksonWriter(g, clazz, ctx));

        g.flush();
        System.out.println("");
    }
View Full Code Here

    public void _testJsonExpr(String expr) throws Exception {
        JsonFactory factory = new JsonFactory();
        JsonParser p = factory.createJsonParser(expr);
        JsonParser rap = JacksonRootAddingParser.createRootAddingParser(p, "root");
        StringWriter sw = new StringWriter();
        JsonGenerator g = factory.createJsonGenerator(sw);
        rap.nextToken();
        while (rap.hasCurrentToken()) {
            g.copyCurrentEvent(rap);
            rap.nextToken();
        }
        g.flush();
        System.out.println(sw);
        assertEquals("{\"root\":" + expr + "}", sw.toString());
    }
View Full Code Here

        String expectedJsonExpr = JSONTestHelper.getResourceAsString(PKG_NAME, jsonExprFilename);
        Marshaller marshaller = jaxbContext.createMarshaller();
        StringWriter resultWriter = new StringWriter();

        JsonFactory jsonFactory = new JsonFactory();
        JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(resultWriter);

        final Stax2JacksonWriter writer = configuration != null
                ? new Stax2JacksonWriter(jsonGenerator, configuration, clazz, jaxbContext) : new Stax2JacksonWriter(jsonGenerator, clazz, jaxbContext);

        marshaller.marshal(jaxbBean, writer);
View Full Code Here

        JAXBContext ctx = JAXBContext.newInstance(classes, props);

        JsonFactory factory = new JsonFactory();
        Writer sWriter = new StringWriter();
        JsonGenerator g;

        g = factory.createJsonGenerator(sWriter);

        Marshaller marshaller = ctx.createMarshaller();
        marshaller.marshal(bean, new Stax2JacksonWriter(g, clazz, ctx));

        g.flush();

        String jsonExpression = sWriter.toString();
        System.out.println(jsonExpression);

        Unmarshaller unmarshaller = ctx.createUnmarshaller();
View Full Code Here

TOP

Related Classes of org.codehaus.jackson.JsonGenerator

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.