All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.adgear.anoa.write.JsonConsumers Maven / Gradle / Ivy

Go to download

Additional functionality complementing the anoa-core module, requiring additional upstream dependencies such as jackson-databind and various jackson dataformats.

There is a newer version: 3.1.2
Show newest version
package com.adgear.anoa.write;

import com.fasterxml.jackson.core.FormatSchema;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.PrettyPrinter;
import com.fasterxml.jackson.core.util.MinimalPrettyPrinter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.util.TokenBuffer;

/**
 * Utility class for writing Jackson records in the JSON format.
 */
public class JsonConsumers extends JacksonConsumersBase<
    ObjectMapper,
    JsonFactory,
    FormatSchema,
    JsonGenerator> {

  static final private PrettyPrinter PRETTY_PRINTER = new MinimalPrettyPrinter("\n");

  public JsonConsumers() {
    super(new ObjectMapper());
  }

  @Override
  public JsonGenerator with(JsonGenerator generator) {
    generator = super.with(generator);
    generator.setPrettyPrinter(PRETTY_PRINTER);
    return generator;
  }

  public TokenBuffer generator() {
    return (TokenBuffer) with(new TokenBuffer(objectCodec, false));
  }

  public TokenBufferWriteConsumer to() {
    return new TokenBufferWriteConsumer(generator());
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy