我有以下课程,基本上是来自网络服务的响应。
public class WSGenericMessage<T> implements Serializable {
private static final long serialVersionUID = 1L;
private Boolean ResponseCode;
private String ResponseMessage;
private Class<T> ResponseData;
public Boolean getResponseCode() {
return ResponseCode;
}
public void setResponseCode(Boolean responseCode) {
ResponseCode = responseCode;
}
public String getResponseMessage() {
return ResponseMessage;
}
public void setResponseMessage(String responseMessage) {
ResponseMessage = responseMessage;
}
public Class<T> getResponseData() {
return ResponseData;
}
public void setResponseData(Class<T> responseData) {
ResponseData = responseData;
}
}
是否可以通过以下方式反序列化 json 字符串:
Gson gson = new Gson();
Type type = new TypeToken<WSGenericMessage<String>>(){}.getType();
gson.fromJson(result, type);
我正进入(状态:
java.lang.UnsupportedOperationException: Attempted to deserialize a java.lang.Class. Forgot to register a type adapter?