Examples of JsonGenerator


Examples of com.fasterxml.jackson.core.JsonGenerator

  final JsonGenerator jsonGenerator;

  public MetricToJsonVisitor(OutputStream os) throws IOException {
    JsonFactory jsonFactory = buildJsonFactory();
    JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(os);

    this.jsonGenerator = jsonGenerator;
  }
View Full Code Here

Examples of com.fasterxml.jackson.core.JsonGenerator

    this.jsonGenerator = jsonGenerator;
  }

  public MetricToJsonVisitor(Writer writer) throws IOException {
    JsonFactory jsonFactory = buildJsonFactory();
    JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(writer);
    jsonGenerator.useDefaultPrettyPrinter();
    this.jsonGenerator = jsonGenerator;
  }
View Full Code Here

Examples of com.fasterxml.jackson.core.JsonGenerator

  public MetricTreeSerializer() {
    this(new JsonFactory());
  }

  public void serialize(MetricTreeBase tree, OutputStream os) throws IOException {
    final JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(os);

    tree.accept(new MetricTreeVisitor() {
      private void writeKey(MetricTreeBase o) throws JsonGenerationException, IOException {
        if (o.getKey() != null) {
          jsonGenerator.writeFieldName(o.getKey());
        }
      }

      @Override
      public void visit(MetricTreeObject o) {
        try {
          writeKey(o);
          jsonGenerator.writeStartObject();
          o.visitChildren(this);
          jsonGenerator.writeEndObject();
        } catch (IOException e) {
          throw new IllegalStateException("Error serializing to JSON", e);
        }
      }

      @Override
      public void visit(MetricTreeString o) {
        try {
          writeKey(o);
          jsonGenerator.writeString(o.getValue());
        } catch (IOException e) {
          throw new IllegalStateException("Error serializing to JSON", e);
        }
      }

      @Override
      public void visit(MetricTreeArray o) {
        try {
          writeKey(o);
          jsonGenerator.writeStartArray();
          o.visitItems(this);
          jsonGenerator.writeEndArray();
        } catch (IOException e) {
          throw new IllegalStateException("Error serializing to JSON", e);
        }
      }

      @Override
      public void visit(MetricTreeInteger o) {
        try {
          writeKey(o);
          jsonGenerator.writeNumber(o.getValue());
        } catch (IOException e) {
          throw new IllegalStateException("Error serializing to JSON", e);
        }
      }

      @Override
      public void visit(MetricTreeFloat o) {
        try {
          writeKey(o);
          jsonGenerator.writeNumber(o.getValue());
        } catch (IOException e) {
          throw new IllegalStateException("Error serializing to JSON", e);
        }
      }
    });

    jsonGenerator.close();
  }
View Full Code Here

Examples of com.fasterxml.jackson.core.JsonGenerator

  @Override
  public final Object encode(final CouchbaseStorable source) {
    Writer writer = new StringWriter();

    try {
      JsonGenerator generator = factory.createGenerator(writer);
      encodeRecursive(source, generator);
      generator.close();
      writer.close();
    } catch (IOException ex) {
      throw new RuntimeException("Could not encode JSON", ex);
    }
View Full Code Here

Examples of com.fasterxml.jackson.core.JsonGenerator

        });

        Analyzer idx = newAnalyzer(srcpath, inclpaths);
        idx.multilineFunType = true;
        JsonFactory jsonFactory = new JsonFactory();
        JsonGenerator symJson = jsonFactory.createGenerator(symOut);
        JsonGenerator refJson = jsonFactory.createGenerator(refOut);
        JsonGenerator docJson = jsonFactory.createGenerator(docOut);
        JsonGenerator[] allJson = {symJson, refJson, docJson};
        for (JsonGenerator json : allJson) {
            json.writeStartArray();
        }
View Full Code Here

Examples of com.fasterxml.jackson.core.JsonGenerator

    return (Map<String,Object>)hstore.jsonRead(parser, token);
  }

  private String generateJson(Map<String, Object> map) throws IOException {
    StringWriter writer = new StringWriter();
    JsonGenerator generator = jsonFactory.createGenerator(writer);
    // wrap in an object to form proper json
    generator.writeStartObject();

    hstore.jsonWrite(generator, "key", map);

    generator.writeEndObject();
    generator.flush();

    return writer.toString();
  }
View Full Code Here

Examples of com.fasterxml.jackson.core.JsonGenerator

  @Test
  public void test_push() throws IOException {

    JsonFactory jsonFactory = new JsonFactory();
    JsonGenerator generator = jsonFactory.createGenerator(new StringWriter());

    PathProperties pathProperties = PathProperties.parse("id,status,name,customer(id,name,address(street,city)),orders(qty,product(sku,prodName))");
    WriteJson writeJson = new WriteJson(null, generator, pathProperties);

    WriteJson.WriteBean rootLevel = writeJson.createWriteBean(null, null);
View Full Code Here

Examples of com.fasterxml.jackson.core.JsonGenerator

    write(object, writer);
    return writer.toString();
  }

  static void write(Object object, Writer writer) throws IOException {
    JsonGenerator generator = jsonFactory.createGenerator(writer);
    write(object, generator);
    generator.close();
  }
View Full Code Here

Examples of com.google.api.client.json.JsonGenerator

  }

  private File createTempFile() throws Exception {
    File result = File.createTempFile("credentials", null);
    result.deleteOnExit();
    JsonGenerator generator =
        JSON_FACTORY.createJsonGenerator(new FileOutputStream(result), Charsets.UTF_8);
    generator.serialize(new FilePersistedCredentials());
    generator.close();
    return result;
  }
View Full Code Here

Examples of com.olabini.jescov.generators.JsonGenerator

    }

    @Then("^the generated JSON should be:$")
    public void the_generated_JSON_should_be(String expectedJSON) throws IOException {
        StringWriter writer = new StringWriter();
        new JsonGenerator(writer).generate(data.getCoverageData());

        Object expected = JSONValue.parse(expectedJSON);
        Object real = JSONValue.parse(writer.toString());

        assertThat(real, is(expected));
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.