Class JsonWriter

java.lang.Object
com.aspectran.utils.json.JsonWriter
Direct Known Subclasses:
ContentsJsonWriter, JsonWriterCloseable

public class JsonWriter extends Object
Converts an object to a JSON formatted string.

If pretty-printing is enabled, the JsonWriter will add newlines and indentation to the written data. Pretty-printing is disabled by default.

Created: 2008. 06. 12 PM 8:20:54

Author:
Juho Jeong
  • Constructor Details

    • JsonWriter

      public JsonWriter(Writer writer)
      Instantiates a new JsonWriter. Pretty printing is enabled by default, and the indent string is set to " " (two spaces).
      Parameters:
      writer - the character-output stream
  • Method Details

    • setStringifyContext

      public void setStringifyContext(StringifyContext stringifyContext)
    • apply

      public <T extends JsonWriter> T apply(StringifyContext stringifyContext)
    • setPrettyPrint

      public void setPrettyPrint(boolean prettyPrint)
    • prettyPrint

      public <T extends JsonWriter> T prettyPrint(boolean prettyPrint)
    • setIndentString

      public void setIndentString(String indentString)
    • indentString

      public <T extends JsonWriter> T indentString(String indentString)
    • setNullWritable

      public void setNullWritable(boolean nullWritable)
    • nullWritable

      public <T extends JsonWriter> T nullWritable(boolean nullWritable)
    • beginObject

      public <T extends JsonWriter> T beginObject() throws IOException
      Begins encoding a new object.
      Throws:
      IOException - if an I/O error has occurred
    • endObject

      public <T extends JsonWriter> T endObject() throws IOException
      Ends encoding the current object.
      Throws:
      IOException - if an I/O error has occurred
    • beginArray

      public <T extends JsonWriter> T beginArray() throws IOException
      Begins encoding a new array.
      Throws:
      IOException - if an I/O error has occurred
    • endArray

      public <T extends JsonWriter> T endArray() throws IOException
      Ends encoding the current array.
      Throws:
      IOException - if an I/O error has occurred
    • name

      public <T extends JsonWriter> T name(String name) throws IOException
      Throws:
      IOException
    • value

      public <T extends JsonWriter> T value(Object value) throws IOException
      Throws:
      IOException
    • writeName

      public void writeName(String name)
      Writes a key name to the writer.
      Parameters:
      name - the string to write to the writer
    • writeValue

      public void writeValue(Object object) throws IOException
      Writes an object to the writer.
      Parameters:
      object - the object to write to the writer.
      Throws:
      IOException - if an I/O error has occurred.
    • writeNull

      public void writeNull() throws IOException
      Writes a "null" string to the writer.
      Throws:
      IOException - if an I/O error has occurred
    • writeNull

      public void writeNull(boolean force) throws IOException
      Writes a "null" string to the writer.
      Parameters:
      force - true if forces should be written null value
      Throws:
      IOException - if an I/O error has occurred
    • writeJson

      public void writeJson(String json) throws IOException
      Writes a string directly to the writer stream without quoting or escaping.
      Parameters:
      json - the string to write to the writer
      Throws:
      IOException - if an I/O error has occurred
    • flush

      public void flush() throws IOException
      Ensures all buffered data is written to the underlying Writer and flushes that writer.
      Throws:
      IOException - if an I/O error has occurred
    • close

      public void close() throws IOException
      Throws:
      IOException
    • toString

      public String toString()
      Overrides:
      toString in class Object