title: Spring boot RestAPI nested JSONObject is empty
body: <p>I have a problem with a JSON request to my REST Api.</p>
  
  <p>My request is something like:</p>
  
  <pre><code>{"task":"get_objects","data":{"guid":"1234"}}
  </code></pre>
  
  <p>But when I want to read the "data" object in my controller it's empty.
  I get an error: <code>org.json.JSONException: JSONObject["guid"] not found.</code></p>
  
  <p><strong>ApiController.java:</strong></p>
  
  <pre><code>import java.util.List;
  
  import org.json.JSONArray;
  import org.json.JSONObject;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.http.HttpStatus;
  import org.springframework.http.ResponseEntity;
  import org.springframework.web.bind.annotation.RequestBody;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RestController;
  
  @RestController
  @RequestMapping("/api")
  public class ApiController {
      @Autowired
      private AssemblyRepository assemblyRepo;
  
      @RequestMapping(method=RequestMethod.POST)
      public ResponseEntity&lt;JSONObject&gt; sendResponse(@RequestBody AppRequest request) {
          String task = request.getTask();
          JSONObject data = request.getData();
          String guid = data.getString("guid");
          String password = data.getString("pwd");
  
          //Do some stuff with the data
      }
  }
  </code></pre>
  
  <p><strong>AppRequest.java:</strong></p>
  
  <pre><code>import org.json.JSONObject;
  
  public class AppRequest {
  
      private String task;
      private JSONObject data;
  
      public String getTask() {
          return task;
      }
  
      public void setTask(String task) {
          this.task = task;
      }
  
      public JSONObject getData() {
          System.out.println("AppRequest getData: " + data);
          return data;
      }
  
      public void setData(JSONObject data) {
          System.out.println("AppRequest getData: " + data);
          this.data = data;
      }
  }
  </code></pre>
  
  <p>I also tried to change the "data" from <code>JSONObject</code> to <code>String</code> but then I get the message <code>Could not read JSON: Can not deserialize instance of java.lang.String out of START_OBJECT token</code>
  I really don't see what I'm doing wrong here ^^</p>