Interface JsonWriter

All Known Implementing Classes:
DefaultJsonWriter, FastJsonWriter

public interface JsonWriter

JsonWriter interface.

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

    • setIndent

      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.
      Parameters:
      indent - a string containing only whitespace.
    • setLenient

      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.
      Parameters:
      lenient - a boolean.
    • setSerializeNulls

      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.
      Parameters:
      serializeNulls - a boolean.
    • getSerializeNulls

      boolean getSerializeNulls()

      getSerializeNulls

      Returns:
      a boolean.
    • beginArray

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

      JsonWriter endArray()
      Ends encoding the current array.
      Returns:
      this writer.
    • beginObject

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

      JsonWriter endObject()
      Ends encoding the current object.
      Returns:
      this writer.
    • name

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

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

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

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

      JsonWriter nullValue()
      Encodes null.
      Returns:
      this writer.
    • cancelName

      JsonWriter cancelName()

      cancelName

      Returns:
      a JsonWriter object.
    • value

      JsonWriter value​(boolean value)
      Encodes value.
      Parameters:
      value - a boolean.
      Returns:
      this writer.
    • value

      JsonWriter value​(double value)
      Encodes value.
      Parameters:
      value - a finite value. May not be NaNs or infinities.
      Returns:
      this writer.
    • value

      JsonWriter value​(long value)
      Encodes value.
      Parameters:
      value - a long.
      Returns:
      this writer.
    • value

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

      JsonWriter rawValue​(java.lang.Object value)
      Encodes value.toString() as is.
      Parameters:
      value - a value .
      Returns:
      this writer.
    • flush

      void flush()
      Ensures all buffered data is written to the underlying StringBuilder and flushes that writer.
    • close

      void close()
      Flushes and closes this writer and the underlying StringBuilder.
    • getOutput

      java.lang.String getOutput()

      getOutput

      Returns:
      the output when the serialization is over