Package org.codehaus.jackson

Examples of org.codehaus.jackson.JsonFactory


        Map<String, Object> props = JSONHelper.createPropertiesForJaxbContext(Collections.<String, Object>emptyMap());
        Class[] classes = new Class[]{clazz};

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


                                final JSONConfiguration configuration) throws Exception {
        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

        Map<String, Object> props = JSONHelper.createPropertiesForJaxbContext(Collections.<String, Object>emptyMap());
        Class[] classes = new Class[]{clazz};

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

        }
    }

    private String _testBeanMarshallNegative(final Class<User> clazz, final JAXBContext context, final Object testInstance)
            throws Exception {
        final JsonFactory factory = new JsonFactory();
        final Writer sWriter = new StringWriter();
        final JsonGenerator jsonGenerator = factory.createJsonGenerator(sWriter);

        final Marshaller marshaller = context.createMarshaller();
        marshaller.marshal(testInstance, new Stax2JacksonWriter(jsonGenerator, clazz, context));

        jsonGenerator.flush();
View Full Code Here

    public void testJsonArray() throws Exception {
        _testJsonExpr("[\"one\",2,\"3\"]");
    }

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

        // first, implicit factory, giving implicit linkage
        ObjectMapper m = new ObjectMapper();
        assertSame(m, m.getJsonFactory().getCodec());

        // and then explicit factory, which should also be implicitly linked
        JsonFactory f = new JsonFactory();
        m = new ObjectMapper(f);
        assertSame(f, m.getJsonFactory());
        assertSame(m, f.getCodec());
    }
View Full Code Here

        return result;
    }

    private Map<String, String> parseJSON(String jsonmessage){
        Map<String, String> parsed = new HashMap<String, String>();
        JsonFactory jf = new JsonFactory();
        try {
            JsonParser parser = jf.createJsonParser(jsonmessage);
            parser.nextToken(); //shift past the START_OBJECT that begins the JSON
            while (parser.nextToken() != JsonToken.END_OBJECT) {
                String fieldname = parser.getCurrentName();
                parser.nextToken(); // move to value, or START_OBJECT/START_ARRAY
                String value = parser.getText();
View Full Code Here

    }
  }

  private String addNode(String json, String fieldName, String id) {

    JsonFactory jsonFactory = new JsonFactory();
    ObjectMapper objectMapper = new ObjectMapper();
    StringWriter stringWriter = new StringWriter();

    try {
      JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(stringWriter);
      ObjectNode objectNode = objectMapper.readValue(json, ObjectNode.class);
      objectNode.put(fieldName, id);
      objectMapper.writeTree(jsonGenerator, objectNode);
      jsonGenerator.flush();
      jsonGenerator.close();
View Full Code Here

  public void consume(String json) throws JsonParseException, IOException {
    if (ApitraryOrmConfiguration.showJson()) {
      showJson(json);
    }

    JsonFactory f = new JsonFactory();
    JsonParser jp = f.createJsonParser(json);

    JsonToken token = jp.nextToken();
    String fieldName = jp.getCurrentName();
    while (!(token == null && fieldName == null)) {
      on(token, fieldName, jp);
View Full Code Here

   * @param json
   *            a {@link java.lang.String} object.
   */
  public void showJson(String json) {
    try {
      JsonFactory jsonFactory = new JsonFactory();
      ObjectMapper objectMapper = new ObjectMapper();
      StringWriter stringWriter = new StringWriter();

      JsonParser jsonParser = jsonFactory.createJsonParser(new StringReader(json));
      JsonNode jsonNode = objectMapper.readTree(jsonParser);
      JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(stringWriter);
      jsonGenerator.useDefaultPrettyPrinter();

      objectMapper.writeTree(jsonGenerator, jsonNode);

      jsonGenerator.flush();
View Full Code Here

TOP

Related Classes of org.codehaus.jackson.JsonFactory

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.