Class JsonWriter<SELF extends JsonWriter<SELF>>

java.lang.Object
java.io.Writer
org.apache.juneau.marshall.serializer.SerializerWriter<SELF>
org.apache.juneau.marshall.json.JsonWriter<SELF>
All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable
Direct Known Subclasses:
BasicJsonWriter, JcsWriter

public abstract class JsonWriter<SELF extends JsonWriter<SELF>> extends SerializerWriter<SELF>
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

    • create

      public static BasicJsonWriter create(Writer out, boolean useWhitespace, int maxIndent, boolean escapeSolidus, char quoteChar, boolean simpleAttrs, boolean trimStrings, UriResolver uriResolver)
      Creates a new JsonWriter instance.

      Provided for subclasses in other packages (e.g. Json5SerializerSession) that need to create JsonWriter instances.

      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.
      Returns:
      A new JsonWriter instance.
    • attr

      public SELF attr(String s)
      Serializes the specified object as a JSON attribute name.
      Parameters:
      s - The object being serialized.
      Can be null (emitted as the literal "null").
      Returns:
      This object.
    • s

      public SELF 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.
    • smi

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

      public SELF stringValue(String s)
      Serializes the specified object as a JSON string value.
      Parameters:
      s - The object being serialized.
      Can be null (nothing is written).
      Returns:
      This object.
    • uriValue

      public SELF uriValue(Object uri)
      Appends a URI to the output.
      Parameters:
      uri - The URI to append to the output.
      Returns:
      This object.