Class HoconWriter

All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

Specialized writer for serializing HOCON format.

Extends SerializerWriter with HOCON-specific methods for unquoted strings, triple-quoted strings ("""), equals sign separator, and formatting options.

See Also:
  • Field Details

    • useNewlineSeparators

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

      protected final boolean useUnquotedStrings
      Use unquoted strings for simple values.
    • useUnquotedKeys

      protected final boolean useUnquotedKeys
      Use unquoted keys when safe.
    • omitRootBraces

      protected final boolean omitRootBraces
      Omit root braces.
    • useMultilineStrings

      protected final boolean useMultilineStrings
      Use triple-quoted """ for strings with newlines.
    • useEqualsSign

      protected final boolean useEqualsSign
      Use = (not :) for key-value separator.
  • Constructor Details

    • HoconWriter

      protected HoconWriter(Writer out, boolean useWhitespace, int maxIndent, boolean trimStrings, boolean useNewlineSeparators, boolean useUnquotedStrings, boolean useUnquotedKeys, boolean omitRootBraces, boolean useMultilineStrings, boolean useEqualsSign, 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.
      useUnquotedStrings - Use unquoted strings for simple values.
      useUnquotedKeys - Use unquoted keys when safe.
      omitRootBraces - Omit root object braces.
      useMultilineStrings - Use """ for multiline strings.
      useEqualsSign - Use = for key-value separator.
      uriResolver - The URI resolver.
  • Method Details

    • key

      public HoconWriter key(String key)
      Writes the key (unquoted or quoted).
      Parameters:
      key - The key to write.
      Can be null (treated as an empty string).
      Returns:
      This object.
    • equalsSign

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

      public HoconWriter objectStart(int depth)
      Writes object start.
      Parameters:
      depth - The current indentation depth.
      Returns:
      This object.
    • objectEnd

      public HoconWriter objectEnd(int depth)
      Writes object end.
      Parameters:
      depth - The current indentation depth.
      Returns:
      This object.
    • arrayStart

      Writes array start.
      Returns:
      This object.
    • arrayEnd

      Writes array end.
      Returns:
      This object.
    • separator

      public HoconWriter separator(int depth)
      Writes member separator (newline or comma).
      Parameters:
      depth - The current indentation depth.
      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 unquoted.
      Parameters:
      value - The value to check.
      Can be null (returns false).
      Returns:
      true if the value can be unquoted.
    • unquotedString

      Writes an unquoted 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.
    • tripleQuotedString

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