Class JsonSchemaElementJsonUtils

java.lang.Object
dev.langchain4j.internal.JsonSchemaElementJsonUtils

public class JsonSchemaElementJsonUtils extends Object
Converts between JsonSchemaElement and JSON Schema Map representation with round-trip fidelity.

Unlike JsonSchemaElementUtils.toMap(JsonSchemaElement), which is optimized for LLM provider APIs and intentionally omits fields like additionalProperties in non-strict mode, this class preserves all fields needed for lossless serialization and deserialization.

See Also:
  • Method Details

    • toMap

      public static Map<String,Object> toMap(JsonSchemaElement element)
      Converts a JsonSchemaElement to a standard JSON Schema Map representation.
    • fromMap

      public static JsonSchemaElement fromMap(Map<String,Object> map)
      Converts a standard JSON Schema Map representation back to a JsonSchemaElement.

      Only the subset of JSON Schema expressible by JsonSchemaElement subtypes is supported. When a map contains additional JSON Schema keywords (e.g., format, pattern, minimum, schema-valued additionalProperties) that cannot be represented by the corresponding typed schema, the entire node falls back to JsonRawSchema to preserve round-trip fidelity. The fallback granularity is per-node: a parent JsonObjectSchema can still be typed even if a child property falls back to raw.

      Throws:
      IllegalArgumentException - if the map contains structurally invalid values (e.g., $ref is not a string, anyOf is not a list, properties contains a non-object value)