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

gcc compilation: size_t not found (installing JLirc on 64 bit system)
Access Personal Certificate from windows using java [closed]
MemorySection.get error trying to load item from custom YAMLConfiguration
AES-RSA-Hybrid - AES BadPaddingException when using on different computers
Diferences in this two approaches to sleep the excecution in java
web.xml properties in WebApplicationInitializer
Factorial logic not giving answer
How to handle null values when doing Collections.sort() with nested objects?
Download in java a webpage which makes AJAX call to load
twitter4j result.nextquery() is giving results from the first page again
How to implement Google Play Game Services, Intellij, libgdx
Accessing Files From Java Applet [duplicate]
2D elastic collision not working properly
Tomcat-7 Error while starting in eclipse Luna, Error starting static Resources
How to design a Pseudorandom Number Generator-Pattern which can be used for testing?
Java, protected access of methods of nested subclass not working. Forced to public [duplicate]

Categories

HOME
reflection
isabelle
alfresco
sqlite3
fsm
yum
basic
modx-revolution
resize
windows-azure-storage
iolanguage
reactcsstransitiongroup
evopdf
firefox-webextensions
introduction
excel-2007
devops
facet
intel-pin
bpel
tinymce-4
fabric8
mmenu
overlap
restlet
adobe-premiere
swisscomdev
sqlite2
botbuilder
estimote
azure-application-gateway
return-value
slickedit
ifs
capacity
watchconnectivity
gridpane
android-textview
database-optimization
mikroc
skype4py
essence
nessus
independentsoft
freedesktop.org
icu4j
jmeter-maven-plugin
iis-arr
generic-programming
ami
system.reflection
fpml
issuu
expected-exception
htmlcleaner
quantlib-swig
dotnetnuke-5
bulkloader
ora-00911
wsdl-2.0
kyotocabinet
angularjs-controller
pvrtc
nsnetservice
cisco-jtapi
funscript
venn-diagram
pysimplesoap
multipage
custom-backend
pydot
table-footer
yui-datatable
disclosure
visitor-statistic
asp.net-mvc-areas
gamequery
mirah
audio-capture
data-acquisition
ajax-forms
misv

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