Class JsonWriter

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

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()
      Instantiates a new JsonWriter. Pretty printing is enabled by default, and the indent string is set to " " (two spaces).
    • JsonWriter

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

    • prettyPrint

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

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

      public <T extends JsonWriter> T dateFormat(String dateFormat)
    • dateTimeFormat

      public <T extends JsonWriter> T dateTimeFormat(String dateTimeFormat)
    • nullWritable

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

      public <T extends JsonWriter> T write(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.
    • writeName

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

      public void writeValue(String value) throws IOException
      Writes a string to the writer. If value is null, write a null string ("").
      Parameters:
      value - the string to write to the writer
      Throws:
      IOException - if an I/O error has occurred
    • writeValue

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

      public void writeValue(Number value) throws IOException
      Writes a Number object to the writer.
      Parameters:
      value - a Number 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
    • beginObject

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

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

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

      public void endArray() throws IOException
      Ends encoding the current array.
      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