java.lang.Object
com.alibaba.dashscope.applications.agentstudio.utils.JsonUtils

public class JsonUtils extends Object
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 Details

    • gson

      public static final com.google.gson.Gson gson
  • Constructor Details

    • JsonUtils

      public JsonUtils()
  • Method Details

    • toJson

      public static String toJson(Object obj)
    • fromJson

      public static <T> T fromJson(String obj, Class<T> clazz)
    • fromJson

      public static <T> T fromJson(String str, Type typeOfT)
    • fromJson

      public static <T> T fromJson(com.google.gson.JsonElement json, Type typeOfT)
    • fromJsonObject

      public static <T> T fromJsonObject(com.google.gson.JsonElement jsonElement, Class<T> clazz)
    • toJsonArray

      public static com.google.gson.JsonArray toJsonArray(Object obj)
    • toJsonObject

      public static com.google.gson.JsonObject toJsonObject(Object obj)
    • toJsonElement

      public static com.google.gson.JsonElement toJsonElement(Object obj)
    • parse

      public static com.google.gson.JsonObject parse(String jsonString)
    • 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 JSON
      com.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 JSON
      com.google.gson.JsonIOException
      com.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 JSON
      com.google.gson.JsonIOException
      com.google.gson.JsonSyntaxException