Package com.fasterxml.jackson.core

Examples of com.fasterxml.jackson.core.JsonGenerator


  @Override
  protected void writeInternal(Object o, HttpOutputMessage outputMessage) throws IOException,
      HttpMessageNotWritableException {
    JsonEncoding encoding = getEncoding(outputMessage.getHeaders().getContentType());
    JsonGenerator jsonGenerator = getObjectMapper().getJsonFactory().createJsonGenerator(outputMessage.getBody(),
        encoding);
    try {
      if (prefixJson) {
        jsonGenerator.writeRaw("{} && ");
      }
      if (isPrettyPrint()) {
        jsonGenerator.useDefaultPrettyPrinter();
      }
      getObjectMapper().writeValue(jsonGenerator, o);
    } catch (JsonGenerationException ex) {
      throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
    }
View Full Code Here


    return strategyJson;
  }

  public static String toString(PartitionStrategy strategy, boolean pretty) {
    StringWriter writer = new StringWriter();
    JsonGenerator gen;
    try {
      gen = new JsonFactory().createGenerator(writer);
      if (pretty) {
        gen.useDefaultPrettyPrinter();
      }
      gen.setCodec(new ObjectMapper());
      gen.writeTree(toJson(strategy));
      gen.close();
    } catch (IOException e) {
      throw new DatasetIOException("Cannot write to JSON generator", e);
    }
    return writer.toString();
  }
View Full Code Here

    return fieldMapping;
  }

  public static String toString(FieldMapping mapping) {
    StringWriter writer = new StringWriter();
    JsonGenerator gen;
    try {
      gen = new JsonFactory().createGenerator(writer);
      gen.setCodec(new ObjectMapper());
      gen.writeTree(toJson(mapping));
      gen.close();
    } catch (IOException e) {
      throw new DatasetIOException("Cannot write to JSON generator", e);
    }
    return writer.toString();
  }
View Full Code Here

    return mappingJson;
  }

  public static String toString(ColumnMapping mapping, boolean pretty) {
    StringWriter writer = new StringWriter();
    JsonGenerator gen;
    try {
      gen = new JsonFactory().createGenerator(writer);
      if (pretty) {
        gen.useDefaultPrettyPrinter();
      }
      gen.setCodec(new ObjectMapper());
      gen.writeTree(toJson(mapping));
      gen.close();
    } catch (IOException e) {
      throw new DatasetIOException("Cannot write to JSON generator", e);
    }
    return writer.toString();
  }
View Full Code Here

  @Override
  protected void writeInternal(Object object, HttpOutputMessage outputMessage)
      throws IOException, HttpMessageNotWritableException {

    JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
    JsonGenerator generator = this.objectMapper.getFactory().createGenerator(outputMessage.getBody(), encoding);
    try {
      writePrefix(generator, object);
      Class<?> serializationView = null;
      Object value = object;
      if (value instanceof MappingJacksonValue) {
        MappingJacksonValue container = (MappingJacksonValue) object;
        value = container.getValue();
        serializationView = container.getSerializationView();
      }
      if (serializationView != null) {
        this.objectMapper.writerWithView(serializationView).writeValue(generator, value);
      }
      else {
        this.objectMapper.writeValue(generator, value);
      }
      writeSuffix(generator, object);
      generator.flush();

    }
    catch (JsonProcessingException ex) {
      throw new HttpMessageNotWritableException("Could not write content: " + ex.getMessage(), ex);
    }
View Full Code Here

   * @throws IOException if writing failed
   */
  protected void writeContent(OutputStream stream, Object object)
      throws IOException {

    JsonGenerator generator = this.objectMapper.getFactory().createGenerator(stream, this.encoding);

    writePrefix(generator, object);
    Class<?> serializationView = null;
    Object value = object;

    if (value instanceof MappingJacksonValue) {
      MappingJacksonValue container = (MappingJacksonValue) value;
      value = container.getValue();
      serializationView = container.getSerializationView();
    }
    if (serializationView != null) {
      this.objectMapper.writerWithView(serializationView).writeValue(generator, value);
    }
    else {
      this.objectMapper.writeValue(generator, value);
    }
    writeSuffix(generator, object);
    generator.flush();
  }
View Full Code Here

  public Object convertToInternal(Object payload, MessageHeaders headers) {
    try {
      if (byte[].class.equals(getSerializedPayloadClass())) {
        ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
        JsonEncoding encoding = getJsonEncoding(getMimeType(headers));
        JsonGenerator generator = this.objectMapper.getFactory().createGenerator(out, encoding);
        this.objectMapper.writeValue(generator, payload);
        payload = out.toByteArray();
      }
      else {
        Writer writer = new StringWriter();
View Full Code Here

    }
    protected void writeView(DataView view, HttpOutputMessage outputMessage)
            throws IOException, HttpMessageNotWritableException {
        JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
        ObjectWriter writer = getWriterForView(view.getView());
        JsonGenerator jsonGenerator =
                writer.getFactory().createGenerator(outputMessage.getBody(), encoding);
        try {
            writer.writeValue(jsonGenerator, view.getData());
        }
        catch (IOException ex) {
View Full Code Here

    }

    private byte[] writeAsJson(RequestEntry[] entries) throws IOException
    {
        ByteArrayOutputStream bytes = new ByteArrayOutputStream(256 + entries.length * 100);
        JsonGenerator jgen = jsonMapper.getFactory().createGenerator(bytes);
        for (RequestEntry entry : entries) {
            jsonMapper.writeValue(jgen, entry);
        }
        jgen.close();
        return bytes.toByteArray();
    }
View Full Code Here

    writeObject(list, createJsonGenerator(out));
  }

  protected JsonGenerator createJsonGenerator(OutputStream out) throws IOException
  {
    final JsonGenerator generator = _jsonFactory.createGenerator(out, _jsonEncoding);
    if (_prettyPrinter != null)
    {
      generator.setPrettyPrinter(_prettyPrinter);
    }
    return generator;
  }
View Full Code Here

TOP

Related Classes of com.fasterxml.jackson.core.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.