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

com.alibaba.dashscope.threads.AnnotationDeserializer Maven / Gradle / Ivy

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

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 AnnotationDeserializer implements JsonDeserializer {

  @Override
  public Object deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
      throws JsonParseException {
    String typeName = json.getAsJsonObject().get("type").getAsString();
    Type type = AnnotationBase.getAnnotationClass(typeName);
    if (type == null) {
      return json.toString();
    }
    return context.deserialize(json, type);
  }
}