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

Message 302 Found while connecting sharepoint
Create a table by combining one column from another table in Java
Java: Many-object variable ( static )
java.lang.AbstractMethodError with javassist and abstract generic classes
Java create an array of object which the 40% of the array length should be object x the other 30% object z and 30% object y [closed]
reading student record from file
InstrumentationLoadTimeWeaver and Java Agent
how to get direction to the shortest path outside circle in google maps android, when my current location is inside 2 or more circles?
Netbeans platform Output window tabs focus shift
ConstraintValidator - Make JPA make the validation after input
Value of “this” in an anonymous class vs a lambda expression
Resizing circular array, in deque implementation
import library doesn't work
Tika App Jar file abruptly ending with causeForTermination being “USER_INTERRUPTION”
How to disable a component from enlarging JPanel in GridBagLayout?
How to implement a chat client

Categories

HOME
listview
debugging
push-notification
relative-path
gis
maven-3
paw-app
malloc
electronics
google-project-tango
serverspec
adfs
gnupg
offline
moonmail
clearcase-ucm
opentracing
normalizr
text-rendering
beyondcompare
nas
accessor
java-7
shopware
spark-jobserver
apache-commons-io
user-interaction
internet-explorer-9
virtualdub
fopen
minitab
compatibility
flink-streaming
instant-messaging
react-chartjs
accelerate-framework
catalog
file-format
serve
scaffold
xcode-extension
streamsets
az-application-insights
ncalc
core-plot
slick-3.0
thin
network-flow
jedis
zip4j
pango
python-webbrowser
domain-model
gabor-filter
setter
pillow
medium.com
wdf
fody
transmitfile
master-slave
python-stackless
comobject
atk4
emailrelay
map-projections
0xdbe
tableau-online
interrupted-exception
notify
device-orientation
modalpopup
tween
oxwall
c3
android-nested-fragment
openexr
p4java
picturefill
fmod
back-stack
jquery-knob
gil
venn-diagram
labwindows
punbb
custom-backend
rfc1123
boost-smart-ptr
sustainable-pace
commodore
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