I have used GSON
for a while, and I think it is quite useful!
Today I encounter a problem, and I think this maybe refer to some advanced usage of GSON
.
here is my class definition:
class ResolvedID
{
private String type;
private HashMap<String,String> data=new HashMap<>(4);
public String getType()
{
return this.type;
}
public void setType(String type)
{
this.type=type;
}
public void put(String K, String V)
{
this.data.put(K,V);
}
}
after that I will do the following in some suitable way, here I just write in a simple way:
I will put some data into this hash map:
ResolvedID id=new ResolvedID();
id.setType("Bachelor");
id.put("school","Computer Science School");
id.put("major","Software Engineering");
id.put("grade","2009");
and I expect GSON might convert it into
{"type":"Bachelor", "data":{"school":"Computer Science School", "grade":"2009", "major":"Software Engineering"}}
But unfortunately I only got
{"type":"Bachelor"}}
Can anyone give some direction for these kind of member field container to convert into json by GSON