Class FastJsonWriter

java.lang.Object
org.dominokit.jacksonapt.stream.impl.FastJsonWriter
All Implemented Interfaces:
JsonWriter

public class FastJsonWriter
extends java.lang.Object
implements JsonWriter

FastJsonWriter class.

Version:
$Id: $
Author:
nicolasmorel
  • Constructor Details

    • FastJsonWriter

      public FastJsonWriter​(java.lang.StringBuilder out)
      Creates a new instance that writes a JSON-encoded stream to out.
      Parameters:
      out - a StringBuilder object.
  • Method Details

    • setIndent

      public final void setIndent​(java.lang.String indent)
      Sets the indentation string to be repeated for each level of indentation in the encoded document. If indent.isEmpty() the encoded document will be compact. Otherwise the encoded document will be more human-readable.
      Specified by:
      setIndent in interface JsonWriter
      Parameters:
      indent - a string containing only whitespace.
    • setLenient

      public final void setLenient​(boolean lenient)
      Configure this writer to relax its syntax rules. By default, this writer only emits well-formed JSON as specified by RFC 4627. Setting the writer to lenient permits the following:
      • Top-level values of any type. With strict writing, the top-level value must be an object or an array.
      • Numbers may be NaNs or infinities.
      Specified by:
      setLenient in interface JsonWriter
      Parameters:
      lenient - a boolean.
    • isLenient

      public boolean isLenient()
      Returns true if this writer has relaxed syntax rules.
      Returns:
      a boolean.
    • setSerializeNulls

      public final void setSerializeNulls​(boolean serializeNulls)
      Sets whether object members are serialized when their value is null. This has no impact on array elements. The default is true.
      Specified by:
      setSerializeNulls in interface JsonWriter
      Parameters:
      serializeNulls - a boolean.
    • getSerializeNulls

      public final boolean getSerializeNulls()

      getSerializeNulls

      Returns true if object members are serialized when their value is null. This has no impact on array elements. The default is true.

      Specified by:
      getSerializeNulls in interface JsonWriter
      Returns:
      a boolean.
    • beginArray

      public FastJsonWriter beginArray()
      Begins encoding a new array. Each call to this method must be paired with a call to JsonWriter.endArray().
      Specified by:
      beginArray in interface JsonWriter
      Returns:
      this writer.
    • endArray

      public FastJsonWriter endArray()
      Ends encoding the current array.
      Specified by:
      endArray in interface JsonWriter
      Returns:
      this writer.
    • beginObject

      public FastJsonWriter beginObject()
      Begins encoding a new object. Each call to this method must be paired with a call to JsonWriter.endObject().
      Specified by:
      beginObject in interface JsonWriter
      Returns:
      this writer.
    • endObject

      public FastJsonWriter endObject()
      Ends encoding the current object.
      Specified by:
      endObject in interface JsonWriter
      Returns:
      this writer.
    • name

      public FastJsonWriter name​(java.lang.String name)
      Encodes the property name.
      Specified by:
      name in interface JsonWriter
      Parameters:
      name - the name of the forthcoming value. May not be null.
      Returns:
      this writer.
    • unescapeName

      public FastJsonWriter unescapeName​(java.lang.String name)
      Encodes the property name without escaping it.
      Specified by:
      unescapeName in interface JsonWriter
      Parameters:
      name - the name of the forthcoming value. May not be null.
      Returns:
      this writer.
    • value

      public FastJsonWriter value​(java.lang.String value)
      Encodes value.
      Specified by:
      value in interface JsonWriter
      Parameters:
      value - the literal string value, or null to encode a null literal.
      Returns:
      this writer.
    • unescapeValue

      public FastJsonWriter unescapeValue​(java.lang.String value)
      Encodes value without escaping it.
      Specified by:
      unescapeValue in interface JsonWriter
      Parameters:
      value - the literal string value, or null to encode a null literal.
      Returns:
      this writer.
    • nullValue

      public FastJsonWriter nullValue()
      Encodes null.
      Specified by:
      nullValue in interface JsonWriter
      Returns:
      this writer.
    • cancelName

      public FastJsonWriter cancelName()

      cancelName

      Specified by:
      cancelName in interface JsonWriter
      Returns:
      a JsonWriter object.
    • value

      public FastJsonWriter value​(boolean value)
      Encodes value.
      Specified by:
      value in interface JsonWriter
      Parameters:
      value - a boolean.
      Returns:
      this writer.
    • value

      public FastJsonWriter value​(double value)
      Encodes value.
      Specified by:
      value in interface JsonWriter
      Parameters:
      value - a finite value. May not be NaNs or infinities.
      Returns:
      this writer.
    • value

      public FastJsonWriter value​(long value)
      Encodes value.
      Specified by:
      value in interface JsonWriter
      Parameters:
      value - a long.
      Returns:
      this writer.
    • value

      public FastJsonWriter value​(java.lang.Number value)
      Encodes value.
      Specified by:
      value in interface JsonWriter
      Parameters:
      value - a finite value. May not be NaNs or infinities.
      Returns:
      this writer.
    • rawValue

      public FastJsonWriter rawValue​(java.lang.Object value)
      Encodes value.toString() as is.
      Specified by:
      rawValue in interface JsonWriter
      Parameters:
      value - a value .
      Returns:
      this writer.
    • flush

      public void flush()
      Ensures all buffered data is written to the underlying StringBuilder and flushes that writer.
      Specified by:
      flush in interface JsonWriter
    • close

      public void close()
      Flushes and closes this writer and the underlying StringBuilder.
      Specified by:
      close in interface JsonWriter
    • getOutput

      public java.lang.String getOutput()

      getOutput

      Specified by:
      getOutput in interface JsonWriter
      Returns:
      the output when the serialization is over