Class HjsonWriter

All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

Specialized writer for serializing Hjson format.

Extends SerializerWriter with Hjson-specific methods for quoteless strings, multiline strings, and formatting options.

See Also:
  • Field Details

    • useNewlineSeparators

      protected final boolean useNewlineSeparators
      Use newlines instead of commas between members.
    • useQuotelessStrings

      protected final boolean useQuotelessStrings
      Use quoteless strings for simple values.
    • useQuotelessKeys

      protected final boolean useQuotelessKeys
      Use quoteless keys when safe.
    • omitRootBraces

      protected final boolean omitRootBraces
      Omit root braces.
    • useMultilineStrings

      protected final boolean useMultilineStrings
      Use multiline ''' for strings with newlines.
    • spacedKeyValueSeparator

      protected final boolean spacedKeyValueSeparator
      Whether to add space after colon.
  • Constructor Details

    • HjsonWriter

      protected HjsonWriter(Writer out, boolean useWhitespace, int maxIndent, boolean trimStrings, boolean useNewlineSeparators, boolean useQuotelessStrings, boolean useQuotelessKeys, boolean omitRootBraces, boolean useMultilineStrings, boolean spacedKeyValueSeparator, UriResolver uriResolver)
      Constructor.
      Parameters:
      out - The writer being wrapped.
      useWhitespace - If true, use indentation and newlines.
      maxIndent - The maximum indentation level.
      trimStrings - If true, trim strings before serialization.
      useNewlineSeparators - Use newlines instead of commas.
      useQuotelessStrings - Use quoteless strings for simple values.
      useQuotelessKeys - Use quoteless keys when safe.
      omitRootBraces - Omit root object braces.
      useMultilineStrings - Use ''' for multiline strings.
      spacedKeyValueSeparator - Add space after colon.
      uriResolver - The URI resolver.
  • Method Details

    • memberSeparator

      public HjsonWriter memberSeparator(int depth)
      Writes member separator (newline or comma).
      Parameters:
      depth - The current indentation depth.
      Returns:
      This object.
    • keyValueSeparator

      Writes key-value separator (: or : ).
      Returns:
      This object.
    • objectStart

      public HjsonWriter objectStart(boolean omitBraces, int depth)
      Writes object start, optionally omitting braces.
      Parameters:
      omitBraces - If true, omit the opening brace.
      depth - The current indentation depth.
      Returns:
      This object.
    • objectEnd

      public HjsonWriter objectEnd(boolean omitBraces, int depth)
      Writes object end, optionally omitting braces.
      Parameters:
      omitBraces - If true, omit the closing brace.
      depth - The current indentation depth.
      Returns:
      This object.
    • arrayStart

      Writes array start.
      Returns:
      This object.
    • arrayEnd

      Writes array end.
      Returns:
      This object.
    • needsQuoting

      public boolean needsQuoting(String key)
      Returns whether the key needs quoting.
      Parameters:
      key - The key to check.
      Can be null (returns true).
      Returns:
      true if the key must be quoted.
    • isSimpleValue

      public boolean isSimpleValue(String value)
      Returns whether the value can be written as quoteless.
      Parameters:
      value - The value to check.
      Can be null (returns false).
      Returns:
      true if the value can be quoteless.
    • quotelessString

      Writes a quoteless string value.
      Parameters:
      value - The value to write.
      Can be null (nothing is written).
      Returns:
      This object.
    • quotedString

      Writes a quoted string with JSON escaping.
      Parameters:
      value - The value to write.
      Can be null (emitted as the literal "null").
      Returns:
      This object.
    • multilineString

      Writes a multiline string using ''' syntax.
      Parameters:
      value - The value to write.
      Can be null (emitted as the literal "null").
      Returns:
      This object.