No converter found for return value of type: class org.json.JSONArray

Viewed 14157

I want to return a JSONArray(org.json.jar) object from spring controller method, this is my java spring controller :

import org.json.JSONArray;
import org.json.JSONException;

@RestController
public class BICOntroller{

@RequestMapping(value="/getStatus", method = RequestMethod.GET)
    public ResponseEntity<JSONArray> getStatus() throws JSONException{
      ResponseEntity<JSONArray> response = null;
      JSONArray arr = new JSONArray();

      JSONObject obj = new JSONObject();
      //process data
      arr.put(obj);

      response = new ResponseEntity<JSONArray>(arr, HttpStatus.OK);
      return response;
  }

}

Angular js call :

            $http({
                url: 'getStatus',
                method: 'GET',
                responseType: 'json'
            }).then(function(response){
                console.log(response);
                return response;
            }, function(error){
                console.log(error);
                return error;
            });

This gives 500 error :

java.lang.IllegalArgumentException: No converter found for return value of type: class org.json.JSONArray

I have included jackson-core-2.7.5.jar and jackson-databind-2.7.5.jar in the class path.

Thanks!

2 Answers

Adding the dependencies did not work for me. What did work is converting the JSONArray to String. FYI I am using Spring Boot Application and was trying to return a JSONArray.

Related