I tried several solutions, and the result of parsing JSON with GSON is always wrong.
I have the following JSON:
{
"account_list": [
{
"1": {
"id": 1,
"name": "test1",
"expiry_date": ""
},
"2": {
"id": 2,
"name": "test2",
"expiry_date": ""
}
}
]
}
In my Java project, I have the following structures:
public class Account{
private int id;
private String name;
private String expiry_date;
public Account()
{
}
public Account(int id, String name, String expiry_date)
{
this.id = id;
this.name = name;
this.expiry_date = expiry_date;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getExpiryDate() {
return expiry_date;
}
}
and
public class AccountList{
private List <Account> account_list;
public void setAccountList(List <Account> account_list) {
this.account_list = account_list;
}
public List <Account> getAccountList() {
return account_list;
}
}
And what am I doing for deserialization:
Data.account_list = new Gson().fromJson(content, AccountList.class);
In the end, I get a List with only one element and with the wrong values. Can you tell me what I'm doing wrong?
Thank.
source
share