Converter not found for return value of type: class org.json.JSONArray
I want to return JSONArray object (org.json.jar) 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 errors:
java.lang.IllegalArgumentException: No converter found for return value of type: class org.json.JSONArray
I turned on jackson-core-2.7.5.jar
and jackson-databind-2.7.5.jar
the class path.
Thank!
+3
source to share
2 answers
Separate from adding dependencies, you may need this.
If you are using not using spring boot, update spring xxx-servlet.xml
with message converters to JSON .
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
</mvc:message-converters>
</mvc:annotation-driven>
if you are using spring boot add dependencies only in pom.xml.
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.4.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.4.3</version>
</dependency>
+2
source to share