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 auto stretch detail band when print order is set to “horizontal” in JasperReport?
JAX-WS and JAX-RS service class instantiation
Java - Adding another String value to existing HashMap Key without overwriting?
Taking Backup of MySQL database using Java [closed]
Create multiple Array lists by using Hashmap
Regex search in a file
String conversion of uint8_t not being recognized in java
fetching meetings using EWS
Cannot connect to database using hibernate with Microsoft Access
Displaying the possible paths of nodes from textfile into jtextfield java swing
Java switch statements outputting the same numbers
Multiple strings at one index of an array list
Index of Highest element in an array
JTextArea, getting last value to use as a counter
Java HEAD/GET request versus Linux request
Grepping file paths in java

Categories

HOME
openlayers
debugging
platform-builder
react-redux
cakephp-2.5
ravendb
synchronization
dacpac
python-unittest
gnupg
quickbooks
commonmark
windows-phone-7
decomposition
uitypeeditor
solaris-10
interop
shared-hosting
visual-composer
jprofiler
introduction
opencover
sox
pepper
facet
tasklet
uisplitview
titanium-mobile
gammu
mmenu
main
scaffold
space-complexity
sharefile
elasticsearch-plugin
ncalc
dynamic-reports
botbuilder
flashair
strptime
revapi
dds
promela
lift-json
memory-alignment
zendesk-app
cudafy.net
query-performance
color-picker
libpng
bstr
blackberry-10
skype4py
jms2
qdialog
simple-framework
wyam
dukescript
arcanist
mdt
zend-route
typeof
starcluster
doskey
xceed-datagrid
jsctypes
spring-io
cos
gridcontrol
eventual-consistency
wsdl-2.0
distutils
tinn-r
chuck
runas
venn-diagram
eclipse-templates
pydot
coercion
hamachi
xfbml
sudzc
coda-slider
sproutcore-2
nintendo-ds
photoshop-cs4
virtual-functions
pascal-fc
text-coloring
spec#
django-notification
ntvdm.exe

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile