title: Restlet Android client - How to map JSON response from ASP.NET Web API to my Java Objects
body: <p>I'm kinda having trouble understand how to make the best and map my JASON response from an ASP.NET Web API server into my Java classes.</p>
  
  <p>I use this code to request the server data.</p>
  
  <pre><code>ClientResource res = new ClientResource(ADDRESS_URL + "/exed/students/");
                 Representation rep = res.get();
                 try {
                     Log.d(TAG, rep.getText());
                 } catch (IOException e) {
                     Log.d(TAG, e.getMessage());
                 }
  </code></pre>
  
  <p>I successfuly can retrieve this JSON representation.</p>
  
  <pre><code>{"$id":"1","StudentId":1,"RowVersion":"AAAAAAAAB9M=","User":{"$id":"2","UserId":1,"Username":"1","Password":"1","UserTypeId":1,"FirstName":"George","LastName":"Taskos","RowVersion":"AAAAAAAAB9I=","Student":{"$ref":"1"},"Teacher":null,"UserType":null}}
  </code></pre>
  
  <p>Now I have these Java classes. </p>
  
  <p>The User.</p>
  
  <pre><code>public class User implements Serializable {
  
      // Private fields
      //
      private int userId;
      private String username;
      private String password;
      private int userTypeId;
      private String firstName;
      private String lastName;
      private String userType;
      private Timestamp rowVersion;
  
      // Setters
      // Getters....
   }
  </code></pre>
  
  <p>And the Student.</p>
  
  <pre><code>public class Student extends User implements Serializable {
  
      // Private fields
      private List&lt;ClassType&gt; classes;
      private List&lt;ExamTaken&gt; examsTaken;
      private Timestamp rowVersionStudent;
  }
  </code></pre>
  
  <p>How to retrieve the representation into my objects. I've seen so much and I think I'm so dizzy right now to get a solution.
  I'm not familiar with Java server side or anything so I guess thats why I get frustrated about stuff I read on the tutorials and I think lots of stuff missing from the site, or not clearly explained.</p>
  
  <p>Any simple example at least on get the values out and get them into my object like I do with SQLite cursors. 
  Deserialization from response would be really great too :)</p>
  
  <p>[EDIT]</p>
  
  <p>After Raw suggestion I ended up with this code.</p>
  
  <pre><code>ClientResource res = new ClientResource(ADDRESS_URL + "/exed/students/");
                 Representation rep = res.get();
  
                 try {
                     JSONObject response = new JSONObject(rep.getText());
                     Log.d(TAG, rep.getText());
                     JSONObject user = response.getJSONObject("User");
                     Log.d(TAG, "User: " + user.toString());
                     JSONObject student = response.getJSONObject("Student");
                     Log.d(TAG, "Student: " + student.toString());
  
                     Log.d(TAG, "FirstName: " + user.getString("FirstName"));
                 } catch (Exception e) {
                     Log.d(TAG, "Exception: " + e.getMessage());
                 }
  </code></pre>
  
  <p>But getting an Exception with this message: Exception: println needs a message</p>
  
  <p>Stacktrace prints this:  Exception: android.util.Log.println_native(Native Method)</p>
  
  <p>and the unhandled exception is this:</p>
  
  <pre><code>03-06 13:07:14.668: ERROR/AndroidRuntime(25353): FATAL EXCEPTION: Thread-13908
          java.lang.NullPointerException: println needs a message
          at android.util.Log.println_native(Native Method)
          at android.util.Log.d(Log.java:155)
          at com.tech.ed.data.access.WebServiceRepository$1.run(WebServiceRepository.java:74)
          at java.lang.Thread.run(Thread.java:856)
  </code></pre>
  
  <p>I don't exactly understand what it means!</p>
  
  <p>Thank you.</p>