Class ToonEncoder

java.lang.Object
io.micronaut.serde.toon.util.ToonEncoder

@Internal @Singleton public final class ToonEncoder extends Object
Writes a JSON tree as a TOON document.

Array form (inline, tabular, keyed-tabular, or list) is chosen by inspecting all elements of an array, or all values of an object for keyed-tabular form, before writing.

An array or keyed object is tabular-eligible only when every element declares the same set of keys (order may vary per element); a differing key set falls back to list form. The header - and the order cells are emitted in for every row - is taken from the first element.

Since:
3.3.0
See Also:
  • Constructor Details

    • ToonEncoder

      public ToonEncoder(SerdeToonConfiguration toonConfiguration)
      Creates a TOON encoder.
      Parameters:
      toonConfiguration - The TOON format configuration
  • Method Details

    • write

      public void write(OutputStream outputStream, io.micronaut.json.tree.JsonNode tree) throws IOException
      Writes the given JSON tree to the output stream as a TOON document.
      Parameters:
      outputStream - The destination stream
      tree - The tree to encode as TOON
      Throws:
      IOException - If the TOON output cannot be written