Hello,
I have tried several solutions and the result of parsing JSON with GSON always gets 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()
{
// Empty constructor
}
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 I do to deserialize is:
Data.account_list = new Gson().fromJson(content, AccountList.class);
At the end I'm getting List with only one element and with wrong values. Can you indicate me plase what I'm doing wrong?
Thanks.