為に -
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;
}
}