0

The json is

{
    "a": "Y",
    "b": "Y",
    "c": "Y",
    "d": "Y",
    "someList": [
        {
            "id": "somevalue"
        },
         
        {
            "id": "somevalue"
        }
    ]
}

for that my java class model is

class Response
   String a,b,c,d;
   ArrayList<Id> idList;
   
  //along with getters and setters.

and below is the implementation of Id class

public class Id {
    private String id;

    public String getid() {
        return id;
    }

    public void setid(String id) {
        this.id = id;
    }
}

Now i parse this as below in a servlet class.

Response details = new Gson().fromJson(request.getReader(),Response.class);

when i print all the string variables like a,b,c,d, it prints but when i try to print the list like

System.out.println(details.getidList());

The result is something like Id@57eff207.ie. it prints the memory location. Now is there any problem with my class structure?. why not able to map the arraylist?

Please help me. Thanks in advance.

1 Answers1

0

Perhaps overriding toString() in Id helps? Something like

@Override
public String toString() {
  return this.id;
}
Bart Barnard
  • 1,128
  • 8
  • 17