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

IndoorAtlas SDK 2.0 : the position of the blue dote does not want to change
Can we use Regular Expression to pass as variables in Tesseract?
How are timeouts handled in JUnit?
Retrieving Facebook Profile Picture
What exactly does the setArgument and getArgument method do?
Using a parameter to instantiate a variable in Java
Get combinations of 3 variables
Logback is not using configuration file
ListNode implementation in scala
Creating an array of Dates for the next 4 sunday (start of weeks)
How to send user data to a new activity using Facebook Login?
Can't read swagger JSON from http://localhost:8080/test-rest/api-docs/index.html
How to set “charset=utf-8” in GeneratePresignedUrlRequest.setContentType(contentType)
Hibernate Search on OneToMany field doesn't work
Cannot resolve package org.junit in my test class
mybatis mapper factory bean and aop

Categories

HOME
xamarin
yii2
google-chrome-extension
hive
deployment
gerrit
pycharm
angular-material
hashmap
grep
cplex
routes
bookshelf.js
ip
fancybox-3
quickbooks
clojurescript
jsdoc
angular-ui
invantive-sql
jprofiler
riot.js
clickonce
ehcache
realex-payments-api
devops
cultureinfo
captiveportal
php-openssl
microsoft-r
emgucv
smb
su
facet
fgetcsv
social-media
twilio-api
siesta-swift
copying
geopositioning
jmonkeyengine
bytecode-manipulation
ws-security
reportingservices-2005
node-gyp
estimote
sencha-touch-2.3
ionicons
alphabet
crypt
mako
zendesk-app
flow-control
specrun
word-vba-mac
abcpdf9
jquery-filter
nxt
azure-sdk
make-install
ios8-today-widget
spim
intel-fortran
lemon
thredds
comobject
spidermonkey
riak-cs
php-ci
sortedlist
pretty-print
cctv
markers
code-access-security
tld
navigationservice
marmalade
java.nio.file
intentservice
quantlib-swig
spring-io
batterylevel
buster.js
gwt-rpc
gridcontrol
random-seed
lcs
distutils
bluepill
venn-diagram
armcc
labwindows
parametric-equations
dotnethighcharts
winbugs14
remember-me
radcombobox
subviews
infrastructure
gamma
modelstate
dbal
photoshop-cs4
temporal-database
ntvdm.exe

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