title: Spring boot REST Api JSON response - No serializer found for class org.json.JSONObject
body: <p>I want to build a RestAPI and return a JSONObject as response.
  Therefore I created this controller:</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) {
  
              //do some stuff with the data from requestBody
  
              List&lt;Assembly&gt; assemblys = assemblyRepo.findAll();
              JSONArray t_sub_objlist = new JSONArray();
              for (Assembly a: assemblys) {
                  JSONObject object = new JSONObject();
                  object.put("obj_type", a.getObjType());
                  object.put("obj_key", a.getObjKey());
                  t_sub_objlist.put(object);
              }
              response.put("t_sub_objlist", t_sub_objlist);
              return new ResponseEntity&lt;JSONObject&gt;(response, HttpStatus.OK);
          }
      }
  </code></pre>
  
  <p>When I print the <code>response</code> to the console everything looks good: <code>{"t_sub_objlist":[{"obj_key":"MS","obj_type":"NT"},{"obj_key":"MV","obj_type":"NT"}]}</code></p>
  
  <p>But when I want to access the API from outside, the first time after restarting the server, I get this error message:</p>
  
  <pre><code>There was an unexpected error (type=Not Acceptable, status=406).
  Could not find acceptable representation
  </code></pre>
  
  <p>And if i try again then this message always comes up:</p>
  
  <pre><code>There was an unexpected error (type=Internal Server Error, status=500).
  Could not write content: No serializer found for class org.json.JSONObject and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) ); nested exception is com.fasterxml.jackson.databind.JsonMappingException
  </code></pre>
  
  <p>I don't know what I'm doing wrong here :)</p>