Class ValueDecoder

java.lang.Object
dev.toonformat.jtoon.decoder.ValueDecoder

public final class ValueDecoder extends Object
Main decoder for converting TOON-formatted strings to Java objects.

Implements a line-by-line parser with indentation-based depth tracking. Delegates primitive type inference to PrimitiveDecoder.

Parsing Strategy:

  • Split input into lines
  • Track current line position and indentation depth
  • Use regex patterns to detect structure (arrays, objects, primitives)
  • Recursively process nested structures
See Also:
  • Method Details

    • decode

      public static Object decode(String toon, DecodeOptions options)
      Decodes a TOON-formatted string to a Java object.
      Parameters:
      toon - TOON-formatted input string
      options - parsing options (delimiter, indentation, strict mode)
      Returns:
      parsed object (Map, List, primitive, or null)
      Throws:
      IllegalArgumentException - if strict mode is enabled and input is invalid
    • decodeToJson

      public static String decodeToJson(String toon, DecodeOptions options)
      Decodes a TOON-formatted string directly to a JSON string using custom options.

      This is a convenience method that decodes TOON to Java objects and then serializes them to JSON.

      Parameters:
      toon - The TOON-formatted string to decode
      options - Decoding options (indent, delimiter, strict mode)
      Returns:
      JSON string representation
      Throws:
      IllegalArgumentException - if strict mode is enabled and input is invalid