我有一个接口。
实现方法如下:
我想使用Gson反序列化一个类,它的实现如下:
当我尝试像这样反序列化它:
这是因为UVW类中使用了接口吗?如果是,那么我该如何反序列化这样的类呢?
public interace ABC {
}
实现方法如下:
public class XYZ implements ABC {
private Map<String, String> mapValue;
public void setMapValue( Map<String, String> mapValue) {
this.mapValue = mapValue;
}
public Map<String, String> getMapValue() {
return this.mapValue
}
}
我想使用Gson反序列化一个类,它的实现如下:
public class UVW {
ABC abcObject;
}
当我尝试像这样反序列化它:
gson.fromJson(jsonString, UVW.class);
它会返回null
。jsonString是UTF_8字符串。这是因为UVW类中使用了接口吗?如果是,那么我该如何反序列化这样的类呢?
ABC
的字段,Gson 如何知道如何反序列化 JSON? - Sotirios DelimanolisRuntimeTypeAdapterFactory
,而这个现在已经在代码库中了(他说没有),然后建议使用JsonDeserializer
,但这基本上已经被弃用了。 - durron597