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

How to sort a list of childnode by the alphabetical order of child node and secondarily by the order of labeled edge in Java
how to connect esp8266 softAp with android app
Partition a Spark Dataframe based on a specific column and dump the content of each partition on a csv
Android file storage
Retrofit 2 RequestBody writeTo() method called twice
How to write a class with generic comparator for sorting list?
JavaFX: How to find the x,y of a specific point along a Circle given only the radius and the center x,y position?
How can I trigger an Action Command artificially?
Appium , not able to read text having content desc and index on an Android native app
Does Logback require Groovy in classpath ? Using logback.xml and not logback.gorovy for configuration
What is the complexity of a code that contains 2 for loops inside an if thats inside a for loop
javax.validation.ConstraintViolationException, ConstraintViolationImpl{interpolatedMessage='may not be null', propertyPath=
Getting the latest record from the collection of documents in MonogDB using MongoTemplate
Spring MVC returns a 404 because of a wrong InternalResourceViewResolver view name
Display button libgdx
WebSocket, authentication in Spring Boot

Categories

HOME
yii2
cloud
coq
oracle11g
tinymce
smarty
react-virtualized
hp-exstream
onedrive
platform-builder
react-router
analysis
cmd
disassembler
networkx
add
adfs
awesome-wm
izpack
rascal
spring-tool-suite
moonmail
decimal
pc
jsdoc
propel
google-cloud-speech
django-cms
firefox-webextensions
visual-composer
custom-wordpress-pages
ehcache
rundeck
tdd
phpfox
log4js-node
compatibility
quote
tasklet
librato
fabric8
uisplitview
data-manipulation
calibre
textmate
jmonkeyengine
web-mining
hockeyapp
ssjs
ensembles
heightmap
react-scripts
boost-multi-index
powercli
epson
nbconvert
url-pattern
heidisql
adxstudio-portals
intrusion-detection
nsviewcontroller
react-native-listview
superstack
master-slave
suffix-tree
freedesktop.org
maven-tomcat-plugin
sdhc
icu4j
thredds
wordml
event-bubbling
graph-drawing
operation
createprocessasuser
unity3d-gui
ami
proj4js
bridge.net
geonetwork
modalpopup
typekit
tablelayout
android-nested-fragment
nsbutton
didselectrowatindexpath
multiprocessor
tws
padarn
yui-compressor
robotics-studio
simba
multipage
newtonscript
labwindows
spring-portlet-mvc
tomcat-valve
krl
winbugs14
android-sdk-2.1
cxxtest
h.323
coda-slider
icanhaz.js
perfect-hash
sustainable-pace
project-hosting
putchar
multiple-languages

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