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

E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
Javafx: No toolkit found exception
How to extract msi file using multiple instances - JAVA?
Compilation failed in Java for “android.permission.READ_NETWORK_USAGE_HISTORY”
Load data from html form, update database and display data on the same page in table using java servlet
How to access chicken class when modding minecraft [closed]
Using an inner class to create a private record for the outer class in java / inner methods visibility
Using Parameter Passing in Netbeans/Java
Is there any way to suppress attribute a isn't defined error in stringTemplate?
How to send data from ListFragment to Fragment
How to read a .dat file and write to a text file?
How to pass through properties in JSON messages with Jackson and MongoDB?
Evict object from ArrayBlockingQueue if full
Combine allMatch, noneMatch and anyMatch on a single stream
Restrict the wrapping of text in JLabel
when the screen is rotated not saved the current Fragment and data

Categories

HOME
gremlin
deezer
onedrive
dot
frameworks
dxl
jpeg
jxls
upload
autotools
slurm
facebook-php-sdk
adobe-analytics
apache-cayenne
windows-phone-7
fallback
django-admin
reactcsstransitiongroup
ab-testing
lldb
grails3
excel-2007
google-search-api
autosys
pingfederate
opentype
log4js-node
dbclient
jspm
atlassian-crucible
vision
junit5
binary-data
create-table
pdb
usbserial
protovis
nssegmentedcontrol
devextreme
automake
hot-module-replacement
libraries
dynamics-crm-2013
uft-api
no-www
long-polling
upstart
zip4j
dds
theming
worksheet
return-value
nstextview
google-perftools
zendesk-app
linode
spring-cache
messenger
angular-cache
multi-level
mathematica-frontend
holder.js
bgp
dlna
ipconfig
metaclass
ruby-2.2
fouc
twirl
facebook-graph-api-v2.4
issuu
article
htmlcleaner
algebraic-data-types
mbr
mcts
geos
apc
buster.js
seed
type-equivalence
http-unit
google-email-migration
runas
manchester-syntax
reddot
jquery-ui-layout
vdsp
xmlspy
audio-capture
backcolor
pascal-fc
post-build
uiq3

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile