Package com.google.genai
Class JsonSerializable
-
- All Implemented Interfaces:
public abstract class JsonSerializableA class that can be serialized to JSON and deserialized from JSON.
-
-
Field Summary
Fields Modifier and Type Field Description public final static StringMAX_READ_LENGTH_PROPERTY
-
Constructor Summary
Constructors Constructor Description JsonSerializable()
-
Method Summary
Modifier and Type Method Description StringtoJson()Serializes the instance to a Json string. static StringtoJsonString(Object object)Serializes an object to a Json string. static JsonNodetoJsonNode(Object object)Serializes an object to a JsonNode. static <T extends JsonSerializable> TfromJsonString(String jsonString, Class<T> clazz)Deserializes a Json string to an object of the given type. static <T extends JsonSerializable> TfromJsonNode(JsonNode jsonNode, Class<T> clazz)Deserializes a JsonNode to an object of the given type. static JsonNodestringToJsonNode(String string)Converts a Json string to a JsonNode. static voidsetMaxReadLength(int maxReadLength)Overrides the default maximum JSON string length (20MB) for the JSON parser. static ObjectMapperobjectMapper()-
-
Method Detail
-
toJsonString
static String toJsonString(Object object)
Serializes an object to a Json string.
-
toJsonNode
static JsonNode toJsonNode(Object object)
Serializes an object to a JsonNode.
-
fromJsonString
@InternalApi() static <T extends JsonSerializable> T fromJsonString(String jsonString, Class<T> clazz)
Deserializes a Json string to an object of the given type. This is for internal use only.
-
fromJsonNode
@InternalApi() static <T extends JsonSerializable> T fromJsonNode(JsonNode jsonNode, Class<T> clazz)
Deserializes a JsonNode to an object of the given type.
-
stringToJsonNode
static JsonNode stringToJsonNode(String string)
Converts a Json string to a JsonNode.
-
setMaxReadLength
static void setMaxReadLength(int maxReadLength)
Overrides the default maximum JSON string length (20MB) for the JSON parser.
Warning: This modifies a global static setting. It will overrides the system property setting via MAX_READ_LENGTH_PROPERTY. This method is not thread-safe.
- Parameters:
maxReadLength- the new maximum string length in bytes (e.g., 100_000_000 for 100MB).
-
objectMapper
static ObjectMapper objectMapper()
-
-
-
-