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

Simplest Java chart library? [closed]
How can I access Java heap objects without a reference?
java source code to html with links from uses to definitions
Find the number of days in a month in Java
Is there a goto statement in Java?
parsing string according to oracle operators with regex
evaluation of a java thread dump
I want to print any text without using Print function in java?
Implementing RSA-SHA1 signature algorithm in Java (creating a private key for use with OAuth RSA-SHA1 signature)
Plotter: What is fixed - the height or the width
How to get Cookies using HttpClient
scroll/search JList when user starts typing
Eclipse not detecting the installed java
How to specify Http Request timeout parameter on Java servlet container
Can enums be subclassed to add new elements?
DIY Form handling, PRG, Validation

Categories

HOME
osgi
drivers
office365api
syntax
filtering
graphql
disassembler
wamp
fancybox
directx
adfs
node-pdfkit
fancybox-3
imacros
row
visual-studio-cordova
workload-scheduler
invantive-sql
evopdf
oracle-coherence
normalizr
java-3d
opencover
core-text
shopware
one-to-many
pepper
uninstall
maquette
saas
atlassian-crucible
srcset
microsoft-chart-controls
ecto
yadcf
protovis
android-kernel
y86
google-api-nodejs-client
ios5
dartium
jquery-bootgrid
xenforo
temporary-files
cookiecutter-django
mapzen
checkboxlist
s
user-accounts
scrollable
jquery-validate
python-webbrowser
dandelion
np-complete
boost-preprocessor
capacity
pillow
hittest
firmata
google-feed-api
log4c
savon
revolution-r
rtbkit
msys
wordml
content-length
rgeo
dukescript
ideamart
processmodel
sortedlist
composite
umbraco6
nsmutabledictionary
dd
jscript.net
bitcoinj
mysql-error-1062
kgdb
imdbpy
uv-mapping
geos
access-rights
clipper
path-separator
fireworks
nsobject
infobox
calling-convention
disclosure
blitz++
rescale
web-architecture
temporal-database
yagni
pascal-fc
defensive-programming
w3wp
post-build

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App