All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alibaba.dashscope.tools.ToolCallGsonDeserializer Maven / Gradle / Ivy

The newest version!
package com.alibaba.dashscope.tools;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import java.lang.reflect.Type;

public class ToolCallGsonDeserializer implements JsonDeserializer {
  @Override
  public Object deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
      throws JsonParseException {
    String toolTypeName = json.getAsJsonObject().get("type").getAsString();
    Type toolType = ToolCallBase.getToolCallClass(toolTypeName);
    if (toolType == null) {
      return json.toString();
    }
    return context.deserialize(json, toolType);
  }
}