Package com.fasterxml.jackson.core

Examples of com.fasterxml.jackson.core.JsonGenerator.writeObject()


        throws IOException
    {
        JsonFactory jf = new MappingJsonFactory();
        StringWriter sw = new StringWriter();
        JsonGenerator gen = jf.createGenerator(sw);
        gen.writeObject(new Pojo());
        gen.close();
        // trimming needed if main-level object has leading space
        String act = sw.toString().trim();
        assertEquals("{\"x\":4}", act);
    }
View Full Code Here


        // regular factory can't do it, without a call to setCodec()
        JsonFactory jf = new JsonFactory();
        try {
            StringWriter sw = new StringWriter();
            JsonGenerator gen = jf.createGenerator(sw);
            gen.writeObject(new Pojo());
            gen.close();
            fail("Expected an exception: got sw '"+sw.toString()+"'");
        } catch (IllegalStateException e) {
            verifyException(e, "No ObjectCodec defined");
        }
View Full Code Here

      jg.setCodec(objectMapper);

      List<MapReducePhase> phases = spec.getPhases();
      phases.get(phases.size() - 1).setKeep(true);
      jg.writeObject(spec);

      jg.flush();

      return out.toString("UTF8");
View Full Code Here

    // testDao.add(test);
    ObjectMapper mapper = new ObjectMapper();
    JsonGenerator jsonGenerator = mapper.getJsonFactory().createJsonGenerator(System.out, JsonEncoding.UTF8);
    // mapper.getJsonFactory().createjsong

    jsonGenerator.writeObject(test);
    System.out.println();
    mapper.writeValue(System.out, test);

    return null;
  }
View Full Code Here

            final List<Annotation> annotations = dps.getAnnotations();
            if (annotations != null) {
              Collections.sort(annotations);
              json.writeArrayFieldStart("annotations");
              for (Annotation note : annotations) {
                json.writeObject(note);
              }
              json.writeEndArray();
            }
           
            if (globals != null && !globals.isEmpty()) {
View Full Code Here

           
            if (globals != null && !globals.isEmpty()) {
              Collections.sort(globals);
              json.writeArrayFieldStart("globalAnnotations");
              for (Annotation note : globals) {
                json.writeObject(note);
              }
              json.writeEndArray();
            }
          }
         
View Full Code Here

                .setCodec(objectMapper);

            generator.writeStartArray();

            for (Cell<ObjectName, String, Object> cell : collectedData.cellSet()) {
                generator.writeObject(new DataPoint(systemTimeMillis, cell, instanceTags));
            }

            generator.writeEndArray();
            generator.flush();
            gzipOutputStream.finish();
View Full Code Here

      jg.setCodec(objectMapper);

      List<MapReducePhase> phases = spec.getPhases();
      phases.get(phases.size() - 1).setKeep(true);
      jg.writeObject(spec);

      jg.flush();

      return out.toString("UTF8");
View Full Code Here

    public String marshall(T obj) {
        try {
            JsonFactory jsonFactory = new MappingJsonFactory();
            StringWriter output = new StringWriter();
            JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(output);
            jsonGenerator.writeObject(obj);
            return output.toString();
        } catch ( Exception e ) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

    public String marshall(T obj) {
        try {
            JsonFactory jsonFactory = new MappingJsonFactory();
            StringWriter output = new StringWriter();
            JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(output);
            jsonGenerator.writeObject(obj);
            return output.toString();
        } catch ( Exception e ) {
            throw new RuntimeException(e);
        }
    }
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.