Class JsonUtils
java.lang.Object
com.alibaba.dashscope.applications.agentstudio.utils.JsonUtils
AgentStudio-owned Gson helpers for the HTTP transport stack.
Number and escaping policies match the former shared utility: LONG_OR_DOUBLE number
parsing, disabled HTML escaping and GsonExclude field exclusion. Model responses with
polymorphic content blocks are parsed through AgentStudioJson.GSON instead.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Tstatic <T> Tstatic <T> Tstatic <T> TfromJsonObject(com.google.gson.JsonElement jsonElement, Class<T> clazz) static com.google.gson.JsonObjectstatic com.google.gson.JsonElementparseReader(com.google.gson.stream.JsonReader reader) Returns the next value from the JSON stream as a parse tree.static com.google.gson.JsonElementparseReader(Reader reader) Parses the specified JSON string into a parse treestatic com.google.gson.JsonElementparseString(String json) Parses the specified JSON string into a parse treestatic Stringstatic com.google.gson.JsonArraytoJsonArray(Object obj) static com.google.gson.JsonElementtoJsonElement(Object obj) static com.google.gson.JsonObjecttoJsonObject(Object obj)
-
Field Details
-
gson
public static final com.google.gson.Gson gson
-
-
Constructor Details
-
JsonUtils
public JsonUtils()
-
-
Method Details
-
toJson
-
fromJson
-
fromJson
-
fromJson
-
fromJsonObject
-
toJsonArray
-
toJsonObject
-
toJsonElement
-
parse
-
parseString
public static com.google.gson.JsonElement parseString(String json) throws com.google.gson.JsonSyntaxException Parses the specified JSON string into a parse tree- Parameters:
json- JSON text- Returns:
- a parse tree of
JsonElements corresponding to the specified JSON - Throws:
com.google.gson.JsonParseException- if the specified text is not valid JSONcom.google.gson.JsonSyntaxException
-
parseReader
public static com.google.gson.JsonElement parseReader(Reader reader) throws com.google.gson.JsonIOException, com.google.gson.JsonSyntaxException Parses the specified JSON string into a parse tree- Parameters:
reader- JSON text- Returns:
- a parse tree of
JsonElements corresponding to the specified JSON - Throws:
com.google.gson.JsonParseException- if the specified text is not valid JSONcom.google.gson.JsonIOExceptioncom.google.gson.JsonSyntaxException
-
parseReader
public static com.google.gson.JsonElement parseReader(com.google.gson.stream.JsonReader reader) throws com.google.gson.JsonIOException, com.google.gson.JsonSyntaxException Returns the next value from the JSON stream as a parse tree.- Parameters:
reader- The json reader.- Returns:
- The `JsonElement` of the reader.
- Throws:
com.google.gson.JsonParseException- if there is an IOException or if the specified text is not valid JSONcom.google.gson.JsonIOExceptioncom.google.gson.JsonSyntaxException
-