Class JacksonUtils
java.lang.Object
uno.anahata.asi.internal.JacksonUtils
A generic utility class for Jackson-based JSON operations. It uses the
centrally configured ObjectMapper from SchemaProvider to ensure consistency
across the application.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final com.fasterxml.jackson.databind.ObjectMapperA vanilla, unconfigured ObjectMapper used strictly for parsing raw, standard JSON structures.private static final com.fasterxml.jackson.databind.ObjectMapperThe primary ObjectMapper instance configured via SchemaProvider for consistent serialization. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TParses a JSON string into a Java object of the specified class.static <T> TParses a JSON string into a Java object of the specified type.static StringSerializes an object to a pretty-printed JSON string.static StringprettyPrintJsonString(String jsonString) Pretty-prints a JSON string.static voidpurifySchema(com.fasterxml.jackson.databind.JsonNode node) Recursively removes redundant and token-heavy fields from a JsonNode.static StringSerializes any Java object into a compact, flat JSON string using the shared mapper.static ObjectConverts any Java object (POJO, Map, List, Primitive) into a "pure" JSON-safe structure containing only standard Java types (Map, List, String, Number, Boolean, null).static <T> TConverts a "pure" JSON-safe structure (Map, List, etc.) into a rich Java POJO.
-
Field Details
-
MAPPER
private static final com.fasterxml.jackson.databind.ObjectMapper MAPPERThe primary ObjectMapper instance configured via SchemaProvider for consistent serialization. -
DEFAULT_MAPPER
private static final com.fasterxml.jackson.databind.ObjectMapper DEFAULT_MAPPERA vanilla, unconfigured ObjectMapper used strictly for parsing raw, standard JSON structures.
-
-
Constructor Details
-
JacksonUtils
public JacksonUtils()
-
-
Method Details
-
toJsonPrimitives
Converts any Java object (POJO, Map, List, Primitive) into a "pure" JSON-safe structure containing only standard Java types (Map, List, String, Number, Boolean, null).This is the "Final Gate" used to ensure that external libraries with "greedy" reflection-based serializers (like the Google GenAI library) never encounter a complex POJO that might trigger forbidden API calls or recursion.
- Parameters:
o- The object to purify.- Returns:
- A pure JSON-safe representation of the object.
-
toPojo
-
parse
Parses a JSON string into a Java object of the specified type.- Type Parameters:
T- The target type.- Parameters:
json- The JSON string to parse.type- The target reflection Type.- Returns:
- The parsed object.
- Throws:
IllegalArgumentException- if parsing fails.
-
parse
-
purifySchema
public static void purifySchema(com.fasterxml.jackson.databind.JsonNode node) Recursively removes redundant and token-heavy fields from a JsonNode. Strips: 'exampleSetFlag', 'types', and 'jsonSchema'. Also removes child descriptions if they match the parent description (redundancy optimization).- Parameters:
node- The JsonNode to purify.
-
serialize
Serializes any Java object into a compact, flat JSON string using the shared mapper.Unlike
prettyPrint(Object), this method does not inject newlines or indentation whitespaces, making it the mathematically accurate choice for token-counting and wire transmission.- Parameters:
o- The object to serialize.- Returns:
- The flat JSON string, or a fallback error string if serialization fails.
-
prettyPrint
-
prettyPrintJsonString
-

