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

Increase the space between two interval in jfreechart for a dual axis bar chart
Android: How to get online or offline user status in quickblox?
How flink authenticates to Elastic Search Sink with shield plugin
How to query jTable from jComboBox?
NullPointerExpection java, even thought value is displaying? [duplicate]
Camel route trigger sequence using rest and MQ
Java standalone app with a database [duplicate]
Get apache server status Java/C
Java server application using websocket with spring framework and jetty for deployment
Gnu library implementing units.dat
New to android programming, trying to create login button that leads to login screen. When I click the login button, the app says “stopped working”
How to stop a java swing timer
Parse Exception while trying to convert date from US/Eastern timezone
Spring Boot : How to get program args with ConfigurationProperties
Caused by: org.apache.http.ProtocolException: Target host is not specified even though its not malformed
Type declaration Eclipse [duplicate]

Categories

HOME
server
tesseract
relay
tizen-web-app
rdf
angular-ui-bootstrap
enterprise-library-5
fancybox
in-app-purchase
uber-api
dacpac
gorm
node-pdfkit
volttron
etl
windows-azure-storage
task
phaser
static-libraries
caml
windows-7-x64
footer
google-pagespeed
dxf
dynamic-featured-image
wpfdatagrid
uninstall
rst2pdf
assistant
google-cloud-nl
skia
directx-10
noraui
avcapturesession
phpfreechat
http-digest
dosbox
xenforo
squib
ensembles
hp-ux
mapzen
sql-server-agent
isbn
modelmapper
wptoolkit
rails-routing
worksheet
celery-task
tizen-native-app
recursive-datastructures
android-cursor
flutterwave
android-fonts
libpng
probability-density
nsfilemanager
disque
asp.net5
freedesktop.org
separator
cannon.js
mutation-observers
jqgrid-formatter
map-projections
umbraco6
applescript-objc
wordpress-theme-customize
client-side-templating
onactivityresult
terminfo
android-radiobutton
article
picturefill
oracle-warehouse-builder
monomac
fmod
multiprocessor
padarn
chronoforms
yui-compressor
plasma
html-editor
hosts-file
nsmanagedobject
jquery-ui-layout
netdna-api
subgurim-maps
horizontal-accordion
krl
oncheckedchanged
imac
radcombobox
blitz++
paster
sortable-tables
routedevent
asp.net-profiles
multi-tier
lzh
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