我编写了一个Java类,使用feignHttp从架构注册表中检索架构。当我尝试检索架构时,抛出以上异常。
客户端类:
import com.google.gson.internal.LinkedTreeMap;
import feign.Feign;
import feign.FeignException;
import feign.gson.GsonDecoder;
import feign.gson.GsonEncoder;
import feign.okhttp.OkHttpClient;
import org.apache.avro.Schema;
import org.apache.avro.SchemaParseException;
public class SchemaRegistryReader {
public Schema getSchemaFromID(String registryURL, String schemaID) throws SchemaParseException, FeignException {
SchemaRegistryClient registryClient = Feign.builder()
.client(new OkHttpClient())
.encoder(new GsonEncoder())
.decoder(new GsonDecoder())
.target(SchemaRegistryClient.class, registryURL);
Object returnedSchema = registryClient.findByID(schemaID);
LinkedTreeMap jsonSchemaObject = ((LinkedTreeMap) returnedSchema);
String jsonSchema = jsonSchemaObject.get("schema").toString();
return new Schema.Parser().parse(jsonSchema);
}
}
方法界面:
import feign.Headers;
import feign.Param;
import feign.RequestLine;
public interface SchemaRegistryClient {
@RequestLine("GET")
Object connect();
@RequestLine("GET /schemas/ids/{id}")
@Headers("Content-Type: application/json")
Object findByID(@Param("id") String id);
}
引发异常:
java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to com.google.gson.internal.LinkedTreeMap at org.wso2.extension.siddhi.map.avro.util.schema.SchemaRegistryReader.getSchemaFromID(SchemaRegistryReader.java:41)
如果可以找到造成这种情况的原因,将会提供很大的帮助。