Class YamlWriter

All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

public class YamlWriter extends SerializerWriter<YamlWriter>
Specialized writer for serializing YAML.
Notes:
  • This class is not intended for external use.
See Also:
  • Constructor Details

    • YamlWriter

      protected YamlWriter(Writer out, boolean useWhitespace, int maxIndent, 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.
      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

    • key

      public YamlWriter key(String s)
      Writes a YAML mapping key.

      If the key needs quoting (contains special YAML characters, starts/ends with whitespace, is empty, or is a YAML reserved word), it will be double-quoted with proper escaping. A colon-space separator is always appended after the key.

      Parameters:
      s - The key name.
      Can be null (written as the literal null).
      Returns:
      This object.
    • keyName

      Writes just the key name portion (with quoting if necessary) but without any separator.
      Parameters:
      s - The key name.
      Can be null (written as the literal null).
      Returns:
      This object.
    • textValue

      Writes a YAML scalar text value.

      If null, writes the literal null. If the string needs quoting (is empty, looks like a boolean/null/number, contains special characters, starts/ends with whitespace, or contains newlines), it will be double-quoted with proper YAML escaping.

      Parameters:
      s - The string value.
      Can be null (written as the literal null).
      Returns:
      This object.
    • uriValue

      public YamlWriter uriValue(Object uri)
      Appends a URI value to the output.

      Resolves the URI and writes it as a double-quoted YAML string.

      Parameters:
      uri - The URI to append to the output.
      Can be null. The effect is implementation-dependent — see UriResolver.resolve(Object).
      Returns:
      This object.
    • yamlIndent

      public YamlWriter yamlIndent(int depth)
      Writes YAML block indentation.

      Writes a newline followed by depth * 2 spaces of indentation.

      Parameters:
      depth - The indentation depth.
      Returns:
      This object.
    • listEntry

      public YamlWriter listEntry(int depth)
      Writes a YAML list entry prefix.

      Writes a newline followed by depth * 2 spaces and a dash-space ("- ") prefix.

      Parameters:
      depth - The indentation depth.
      Returns:
      This object.