Disarray JSON response using GSON using Java

I am trying to parse the following JSON response using GSON:

{
  "total": 15,
  "page": 2,
  "pagesize": 10,
  "rep_changes": [
    {
      "user_id": 2341,
      "post_id": 2952530,
      "post_type": "question",
      "title": "unprotected access to member in property get",
      "positive_rep": 5,
      "negative_rep": 0,
      "on_date": 1275419872
    },
   {
      "user_id": 2341,
      "post_id": 562948,
      "post_type": "question",
      "title": "Do you have any recommendations on Blend/XAML books/tutorials for designers?",
      "positive_rep": 20,
      "negative_rep": 0,
      "on_date": 1270760339
    }
  ....
}

These are the two classes that I defined (each class contains the corresponding getters and setters):

public class Reputation {
    private int total;
    private int page;
    private int pagesize;
    private List<RepChanges> rep_changes;

public class RepChanges {
    private int user_id;
    private int post_id;
    private String post_type;
    private String title;
    private int positive_rep;
    private int negative_rep;
    private long on_date;

I was unable to parse the RepChanges class in the rep_changes attribute in the reputation class. Any thoughts?

Note. I was able to analyze the total number of pages and pages (these are not complex attributes). This is what I did:

To analyze the total number of pages and pages, I used (and worked fine):

Gson gson = new Gson();
Reputation rep = gson.fromJson(jsonText, Reputation.class);

//doing this works:
int page = rep.getPage();
System.out.println(page);

However, when executed:

List<RepChanges> rep_changes = rep.getRep_changes();
for(RepChanges r : rep_changes){
    System.out.println(r.toString());
}

I (technically) do not receive an error message, but the following (which looks like a memory location):

stackoverflow.objects.RepChanges@116bb691
+5
source share
1 answer

Repchanges toString(), :

public String toString ()
{
    return "RepChanges [user_id=" + user_id + 
            ", post_id=" + post_id + 
            ", post_type=" + post_type + 
            ", title=" + title + 
            ", positive_rep=" + positive_rep + 
            ", negative_rep=" + negative_rep + 
            ", on_date=" + on_date + "]";
}
+3

All Articles