为了 -
Config rfqObj = new Gson().fromJson(data, new TypeToken<Config>() {}.getType());
我收到以下异常 -
给定具有根本原因的类型, JsonDeserializer
main.java.com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter@30de3c87
无法反序列化 json 对象 {} 。main.java.com.google.gson.ParameterizedTypeImpl@7c3d0336]
java.lang.IllegalStateException: This is not a JSON Array
JSON数据是 -
{
"quantities": {
"142": "0",
"143": "20",
"144": "25"
},
"characteristics": {},
"details": {
"8": "HT Test Report",
"9": "Others",
"13": "nTest"
},
"materials": {},
"additionalProcesses": {},
"suppliers": {}
}
这是 POJO -
public class Config {
Map<Long, String> quantities = new HashMap<Long, String>();
Map<Long, String> characteristics = new HashMap<Long, String>();
Map<Long, String> details = new HashMap<Long, String>();
Map<Long, String> materials = new HashMap<Long, String>();
Map<Long, String> additionalProcesses = new HashMap<Long, String>();
public Set<Suppliers> suppliers = new HashSet();
//this is for the nested class
public static class Suppliers {
// defining attributes of this class
public Long id;
public String name;
public Long contactId;
public String contactInfo;
public String contactMethod;
public String contactName;
public String message;
}
}