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

Accessing .properties file in webcontent folder form servlet project [closed]
Drag and drop richfaces problem
How to preserve the CAcerts keystore on Mac across updates?
Upload file to google calendar
Different languages
how can add photos from flickr?
Reading JSon String with Gson
Calculate whether an IP address is in a specified range in Java
How to resolve Groovy conflict with Apache Common Logging?
incompatible types - found java.util.Iterator(Lot) but expected java.util.Iterator (java.lang.String)
Java ArrayList: Get Distinct Values from ArrayList which contain HashMap
Java multiple classepath with :classes directive
Why does my JTextArea overflow the frame in GroupLayout?
returning values in a applet?
NBP rich client in a multi-tier enterprise application?
set ImageView src via ListAdapter

Categories

HOME
client
vbscript
keycloak
omnet++
pycharm
sd-card
sqlite3
baqend
angular-ui-bootstrap
ebean
ezpublish
spring-kafka
rascal
modx-revolution
spring-tool-suite
workload-scheduler
foselasticabundle
database-replication
text-rendering
firefox-webextensions
cx-freeze
kudan
captiveportal
jndi
shopware
one-to-many
brunch
traffic
spring-mybatis
instant-messaging
http-referer
io-redirection
xenforo
opshub
bootstrapper
lumberjack
mesos-chronos
fakeiteasy
http-redirect
total-commander
wptoolkit
cubic-spline
xml-documentation
idisposable
composite-key
magma
font-size
sybase-asa
titanium-android
redundancy
query-performance
wdf
libpng
infix-notation
pcf
nsfilemanager
firebaseui
thredds
comobject
iis-arr
pundit
angular-leaflet-directive
responsive-images
sysinternals
composite
remobjects
notify
qpainter
gadt
qcodo
rdtsc
gulp-less
internet-connection
code-access-security
document-classification
zend-route
ceil
seaside
datagridviewcolumn
java.nio.file
listings
blending
dbconnection
bulkloader
rabl
sabredav
robotics-studio
bitsharp
rdoc
broken-links
word-processor
jspinclude
ocx
zpt
xdomainrequest
horizontal-accordion
xtype
android-sdk-2.1
site.master
modelstate
routedevent
mirah
castle-monorail
rescale
thunderbird-lightning
web-architecture
ugc
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