java


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


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!
Apart from adding dependencies, you may need this.
If you are not using spring boot, update your spring xxx-servlet.xml with message converters for 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, adding dependencies in pom.xml alone will suffice.
<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>

Related Links

Servlet returning response as HTML instead of JSON
NginX times out connecting to java app
Maven pom with zipped native dll in classpath
Issue trying project euler #3
servlet could not create cookie file in IE11
RegEx for QRadar SIEM
Working with String value in Build/Ant file in Java
Moving Java Object using UFT and VBScript
CamelContext(wsBlueprintContext) due Already a destination on
In apache spark, how do I collect a column of mllib Vector into a list after groupBy()?
Design choices for method specific variables
Trying to make a method that shows the guessed letters for the game Hang Man (Java)
JTable filter data not working properly
Android Alarm Scheduling with repeats
How can I customise the number format for Joda Time date formatting?
R text mining: error in extracting bigrams from corpus during tokenization step

Categories

HOME
openstack
mockito
homebrew
iterator
iot
grep
bpmn
youtube-dl
spring-jdbc
graphql
yum
pheatmap
google-translate
vifm
floating-action-button
circular-dependency
usergrid
size
fortumo
flask-wtforms
pc
evopdf
django-cms
crystal-reports-2008
jtextfield
grails3
format-specifiers
crystal-reports-2010
emgucv
javacv
gitignore
libssl
typed.js
perlin-noise
lxd
uiswipegesturerecognizer
cloud-code
simplexml
espeak
impersonation
grid.mvc
quadratic-programming
unixodbc
netcdf4
scorm
wso2carbon
google-datalayer
veracode
feeds
ifs
sqlbulkcopy
blacklist
spring-android
google-web-starter-kit
skype4py
suffix-tree
livequery
wapiti
associative-array
natvis
separator
maven-tomcat-plugin
django-unittest
wyam
riak-cs
responsive-images
bridge.net
jsapi
javax.mail
mdt
fluentautomation
picturefill
stxxl
monomac
html5-notifications
prettify
gnu-smalltalk
c18
sqlperformance
sabredav
wsdl-2.0
mt
dice
manchester-syntax
pysimplesoap
objective-c-2.0
wse3.0
adk
winbugs14
lang
revisions
multi-tier
photoshop-cs4
premature-optimization
aquaticprime
genealogy
msdev

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App