title: Convert class into a JSONObject
body: <p>I have several classes like this. I want to convert the classes into JSONObject format. </p>
  
  <pre><code>import java.io.Serializable;
  
  import com.google.gson.annotations.SerializedName;
  
  public class User implements Serializable {
      private static final long serialVersionUID = 1L;
      @SerializedName("id")
      private Integer mId;
      @SerializedName("name")
      private String mName = "";
      @SerializedName("email")
      private String mEmail;
  
      public Integer getId() {
          return mId;
      }
      public void setId(Integer id) {
          mId = id;
      }
  
      public String getName() {
          return mName;
      }
      public void setName(String name) {
          mName = name;
      }
  
      public String getEmail() {
          return mEmail;
      }
      public void setEmail(String email) {
          mEmail = email;
      }
  }
  </code></pre>
  
  <p>I know that I can convert these classes to JSONObject format as follows:</p>
  
  <pre><code>    User user = new User();
      JSONObject jsonObj = new JSONObject();
      try {
          jsonObj.put("id", user.getId());
          jsonObj.put("name", user.getName());
          jsonObj.put("email", user.getEmail());
      } catch (JSONException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  </code></pre>
  
  <p>The problem is that I need to do this for a lot of different classes that are much longer than this across a lot of files. Can I use GSON to fill the JSONObject from myClass so that I don't need to edit every time the class structure changes? </p>
  
  <p>The following returns a JSON string but I need it as an Object as when I send it to the system that sends the requests via a REST API it sends with unwanted quotation marks. </p>
  
  <pre><code>User user = new User();
  Gson gson = new Gson();
  Object request = gson.toJson(user);
  </code></pre>
  
  <p>When I use this in another JSON builder that asks for an Object I get </p>
  
  <pre><code>{"request":"{"id":"100","name":"Test Name","email":"test@example.com"}"}
  </code></pre>
  
  <p>When I want</p>
  
  <pre><code>{"request":{"id":"100","name":"Test Name","email":"test@example.com"}}
  </code></pre>