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

Adding Drawables from assets into ListView
Struts2 : Trimming String properties after Action invoke/execute
spark application does not stop when multiple threads share the same spark context
Spring MVC Upload file in form no file validation
sqlmap inject via parameters in soap body?
Java: Authentication and Authorization with iOS/Andorid/Angular as client
Tango SDK can't set custom exposure or ISO
How do I complete numerous jobs with a few threads giving each the same timeout to complete?
Maven profiles dependency inside other dependency in JxBrowser
Fitnesse error when used with spotify maven plugin and docker
Libgdx Refactor a class with texture
Timing method inside multiple for in java
Spring REST Integration tests, entity is not deleted
String.concat used as a BiFunction
User Java Regex to extract data from String
getting unhandled exception in try catch block java

Categories

HOME
cakephp
listview
hook
proxy
zeromq
mediawiki
hp-exstream
grep
xmpp
google-oauth
blueprintjs
fingerprint
ezpublish
azure-storage-tables
uber-api
autotools
synchronization
midi
mapserver
resize
n-gram
progressive-web-apps
reactive-cocoa
lucene.net
reverse-proxy
tokenize
chromium-embedded
crystal-reports-2010
emgucv
facet
rst2pdf
wtx
bpel
react-chartjs
contact-form
http-referer
html5-fullscreen
wixsharp
git-merge
retina-display
automake
lto
neuroscience
streamsets
sfdc
reportingservices-2005
texmaker
thin
cubic-spline
youcompleteme
zip4j
paxos
sage-one
return-value
dotnetzip
directory-structure
sqlclient
feeds
knpmenubundle
orthogonal
background-service
google-feed-api
passport-google-oauth
removechild
mathematica-frontend
fuzzy-search
markojs
simplewebrtc
python-stackless
pickadate
captivenetwork
rhino-servicebus
tform
pyke
netmq
browser-link
lemon
comobject
rgeo
sframe
mono-embedding
sailfish-os
remobjects
angular-local-storage
lustre
pick
gadt
device-manager
zend-route
uitouch
bundles
html5-notifications
pyhdf
dataadapter
factory-method
specification-pattern
path-separator
buildr
php-parser
infobox
hamachi
yetanotherforum
celltable
lang
infrastructure
gamma
gin
jquery-ui-droppable
ctp4
nerddinner
zune

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