Class JToon

java.lang.Object
dev.toonformat.jtoon.JToon

public final class JToon extends Object
Main entry point for encoding and decoding TOON (Token-Oriented Object Notation) format. Provides static methods to convert between Java objects, JSON strings, and TOON format.
  • Method Details

    • encode

      public static String encode(Object input)
      Encodes a Java object to JToon format using default options.

      The object is first normalized (Java types are converted to JSON-compatible representations), then encoded to JToon format.

      Parameters:
      input - The object to encode (can be null)
      Returns:
      The JToon-formatted string
    • encode

      public static String encode(Object input, EncodeOptions options)
      Encodes a Java object to JToon format using custom options.

      The object is first normalized (Java types are converted to JSON-compatible representations), then encoded to JToon format.

      Parameters:
      input - The object to encode (can be null)
      options - Encoding options (indent, delimiter, length marker)
      Returns:
      The JToon-formatted string
    • encodeJson

      public static String encodeJson(String json)
      Encodes a plain JSON string to TOON format using default options.

      This is a convenience overload that parses the JSON string and encodes it without requiring callers to create a JsonNode or intermediate objects.

      Parameters:
      json - The JSON string to encode (must be valid JSON)
      Returns:
      The TOON-formatted string
      Throws:
      IllegalArgumentException - if the input is not valid JSON
    • encodeJson

      public static String encodeJson(String json, EncodeOptions options)
      Encodes a plain JSON string to TOON format using custom options.

      Parsing is delegated to JsonNormalizer.parse(String) to maintain separation of concerns.

      Parameters:
      json - The JSON string to encode (must be valid JSON)
      options - Encoding options (indent, delimiter, length marker)
      Returns:
      The TOON-formatted string
      Throws:
      IllegalArgumentException - if the input is not valid JSON
    • decode

      public static Object decode(String toon)
      Decodes a TOON-formatted string to Java objects using default options.

      Returns a Map for objects, List for arrays, or primitives (String, Number, Boolean, null) for scalar values.

      Parameters:
      toon - The TOON-formatted string to decode
      Returns:
      Parsed object (Map, List, primitive, or null)
      Throws:
      IllegalArgumentException - if strict mode is enabled and input is invalid
    • decode

      public static Object decode(String toon, DecodeOptions options)
      Decodes a TOON-formatted string to Java objects using custom options.

      Returns a Map for objects, List for arrays, or primitives (String, Number, Boolean, null) for scalar values.

      Parameters:
      toon - The TOON-formatted string to decode
      options - Decoding options (indent, delimiter, 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)
      Decodes a TOON-formatted string directly to a JSON string using default 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
      Returns:
      JSON string representation
      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