Package ai.libs.jaicore.logging
Class ToJSONStringUtil
- java.lang.Object
-
- ai.libs.jaicore.logging.ToJSONStringUtil
-
public class ToJSONStringUtil extends java.lang.Object
This class provides a util for serializing specific contents of an object in the form of a JSON string. Furthermore, it recursively extracts json trees from object variables and mounts them into the current tree.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static com.fasterxml.jackson.databind.JsonNode
parseObjectToJsonNode(java.lang.Object fieldValue, com.fasterxml.jackson.databind.ObjectMapper om)
Parses an object to JSON depending on the objects capabilities to express itself in JSON format or not.static java.lang.String
toJSONString(java.lang.String rootName, java.util.Map<java.lang.String,java.lang.Object> fields)
This method should be used with caution, as it introduces an additional layer for naming the object to serialize in json format withrootName
.static java.lang.String
toJSONString(java.util.Map<java.lang.String,java.lang.Object> fields)
Util for transforming an object into a JSON string representation.
-
-
-
Method Detail
-
toJSONString
public static java.lang.String toJSONString(java.util.Map<java.lang.String,java.lang.Object> fields)
Util for transforming an object into a JSON string representation. It requires to pass a map of object variables of the object to serialize in form of a map.- Parameters:
fields
- The map of object variables to be serialized as a json string.- Returns:
- A string representing the object contents in JSON format.
-
toJSONString
public static java.lang.String toJSONString(java.lang.String rootName, java.util.Map<java.lang.String,java.lang.Object> fields)
This method should be used with caution, as it introduces an additional layer for naming the object to serialize in json format withrootName
. Thus, it introduces another layer in the object hierarchy.- Parameters:
rootName
- The name of the object.fields
- The map of object variables to be serialized as a json string.- Returns:
- A string representing the object contents in JSON format.
-
parseObjectToJsonNode
public static com.fasterxml.jackson.databind.JsonNode parseObjectToJsonNode(java.lang.Object fieldValue, com.fasterxml.jackson.databind.ObjectMapper om)
Parses an object to JSON depending on the objects capabilities to express itself in JSON format or not.- Parameters:
fieldValue
- The object to be parsed.om
- The object mapper that is to be used for parsing.- Returns:
- A JsonNode representing the parsed object.
-
-