Class JsonWriter

All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

public final class JsonWriter extends SerializerWriter
Specialized writer for serializing JSON.
Notes:
  • This class is not intended for external use.
See Also:
  • Constructor Details

    • JsonWriter

      protected JsonWriter(Writer out, boolean useWhitespace, int maxIndent, boolean escapeSolidus, char quoteChar, boolean simpleAttrs, boolean trimStrings, UriResolver uriResolver)
      Constructor.
      Parameters:
      out - The writer being wrapped.
      useWhitespace - If true, tabs and spaces will be used in output.
      maxIndent - The maximum indentation level.
      escapeSolidus - If true, forward slashes should be escaped in the output.
      quoteChar - The quote character to use (i.e. '\'' or '"')
      simpleAttrs - If true, JSON attributes will only be quoted when necessary.
      trimStrings - If true, strings will be trimmed before being serialized.
      uriResolver - The URI resolver for resolving URIs to absolute or root-relative form.
  • Method Details

    • stringValue

      Serializes the specified object as a JSON string value.
      Parameters:
      s - The object being serialized.
      Returns:
      This object.
    • attr

      public JsonWriter attr(String s)
      Serializes the specified object as a JSON attribute name.
      Parameters:
      s - The object being serialized.
      Returns:
      This object.
    • uriValue

      Appends a URI to the output.
      Parameters:
      uri - The URI to append to the output.
      Returns:
      This object.
    • smi

      public JsonWriter smi(int depth)
      Performs an indentation only if we're currently past max indentation.
      Parameters:
      depth - The current indentation depth.
      Returns:
      This object.
    • s

      public JsonWriter s(int indent)
      Adds a space only if the current indentation level is below maxIndent.
      Parameters:
      indent - The number of spaces to indent.
      Returns:
      This object.
    • cr

      public JsonWriter cr(int depth)
      Description copied from class: SerializerWriter
      Performs a carriage return.

      Adds a newline and the specified number of tabs (if the useWhitespace setting is enabled) to the output.

      Overrides:
      cr in class SerializerWriter
      Parameters:
      depth - The indentation.
      Returns:
      This object.
    • cre

      public JsonWriter cre(int depth)
      Description copied from class: SerializerWriter
      Performs a carriage return at the end of a line.

      Adds a newline and the specified number of tabs (if the useWhitespace setting is enabled) to the output.

      Overrides:
      cre in class SerializerWriter
      Parameters:
      depth - The indentation.
      Returns:
      This object.
    • appendln

      public JsonWriter appendln(int indent, String text)
      Description copied from class: SerializerWriter
      Writes an indent (if the useWhitespace setting is enabled), followed by text, followed by a newline (if the useWhitespace setting is enabled).
      Overrides:
      appendln in class SerializerWriter
      Parameters:
      indent - The number of tabs to indent.
      text - The text to write.
      Returns:
      This object.
    • appendln

      public JsonWriter appendln(String text)
      Description copied from class: SerializerWriter
      Writes the specified text followed by a newline (if the useWhitespace setting is enabled).
      Overrides:
      appendln in class SerializerWriter
      Parameters:
      text - The text to write.
      Returns:
      This object.
    • append

      public JsonWriter append(int indent, String text)
      Description copied from class: SerializerWriter
      Writes an indent (if the useWhitespace setting is enabled), followed by text.
      Overrides:
      append in class SerializerWriter
      Parameters:
      indent - The number of tabs to indent.
      text - The text to write.
      Returns:
      This object.
    • append

      public JsonWriter append(int indent, char c)
      Description copied from class: SerializerWriter
      Writes an indent (if the useWhitespace setting is enabled), followed by text.
      Overrides:
      append in class SerializerWriter
      Parameters:
      indent - The number of tabs to indent.
      c - The character to write.
      Returns:
      This object.
    • s

      public JsonWriter s()
      Description copied from class: SerializerWriter
      Adds a whitespace character to the output if the useWhitespace setting is enabled.
      Overrides:
      s in class SerializerWriter
      Returns:
      This object.
    • w

      public JsonWriter w(char value)
      Description copied from class: SerializerWriter
      Writes the specified character to the writer.
      Overrides:
      w in class SerializerWriter
      Parameters:
      value - The character to write.
      Returns:
      This object.
    • w

      public JsonWriter w(String value)
      Description copied from class: SerializerWriter
      Writes the specified string to the writer.
      Overrides:
      w in class SerializerWriter
      Parameters:
      value - The string to write.
      Returns:
      This object.
    • q

      public JsonWriter q()
      Description copied from class: SerializerWriter
      Adds the quote character specified by the quoteChar setting to the output.
      Overrides:
      q in class SerializerWriter
      Returns:
      This object.
    • i

      public JsonWriter i(int indent)
      Description copied from class: SerializerWriter
      Writes an indent to the writer if the useWhitespace setting is enabled.
      Overrides:
      i in class SerializerWriter
      Parameters:
      indent - The number of tabs to indent.
      Returns:
      This object.
    • nl

      public JsonWriter nl(int indent)
      Description copied from class: SerializerWriter
      Writes a newline to the writer if the useWhitespace setting is enabled.
      Overrides:
      nl in class SerializerWriter
      Parameters:
      indent - The current indentation level.
      Returns:
      This object.
    • append

      public JsonWriter append(Object text)
      Description copied from class: SerializerWriter
      Writes the specified text to the writer if it isn't null.
      Overrides:
      append in class SerializerWriter
      Parameters:
      text - The text to write.
      Returns:
      This object.
    • append

      public JsonWriter append(String text)
      Description copied from class: SerializerWriter
      Writes the specified text to the writer if it isn't null.
      Overrides:
      append in class SerializerWriter
      Parameters:
      text - The text to write.
      Returns:
      This object.
    • appendIf

      public JsonWriter appendIf(boolean b, String text)
      Description copied from class: SerializerWriter
      Writes the specified text to the writer if b is true.
      Overrides:
      appendIf in class SerializerWriter
      Parameters:
      b - Boolean flag.
      text - The text to write.
      Returns:
      This object.
    • appendIf

      public JsonWriter appendIf(boolean b, char c)
      Description copied from class: SerializerWriter
      Writes the specified text to the writer if b is true.
      Overrides:
      appendIf in class SerializerWriter
      Parameters:
      b - Boolean flag.
      c - The text to write.
      Returns:
      This object.
    • append

      public JsonWriter append(char c)
      Specified by:
      append in interface Appendable
      Overrides:
      append in class SerializerWriter