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

NoUniqueBeanDefinitionException when injecting JpaRepository to Generic class
JavaFX tableView, when adding items to table A, table B take them too?
ANDROID JSON jsonObject with value shows NullPointerException error [duplicate]
java.lang.ArrayIndexOutOfBoundsException: length=4; index=6 [duplicate]
Using super and toString to update JTextArea
Is it possible to detect null references with JSoup?
Adding 1 one on to an integer each time? [closed]
How to decrypt an encrypted AES file using base64 Symmetric key and IV
Java file writer
Running junit plugin test suite fails due to concurrent modification exception In arrayList.java
Problems with comparing characters of integer casted as a String [closed]
How to change values in the SET Method
spring security is remember me user authenticated by username
replacing certain characters in string in java
Android / Java: Show GUI on “off-screen” (Always-On Display…)
Solrj - cannot inherit from final class error due to HTTPSolrServer

Categories

HOME
java
vbscript
dictionary
kde
angular-material
view
framework7
cakephp-2.5
cross-browser
dax
resize
visual-studio-2005
fortumo
ibm-odm
flask-wtforms
jsprit
django-simple-history
aurigma
nhibernate-envers
django-cms
lucene.net
karma-jasmine
scichart
emulator
reverse-proxy
accessor
wkwebview
language-agnostic
microsoft-sync-framework
javacv
fgetcsv
entitlements
jaxb2
bpel
sql-server-2012-express
xquery-3.0
uisplitview
google-qpx-express-api
form-data
android-kernel
bytecode-manipulation
simplexml
adobe-premiere
code-search-engine
avro4s
midl
vao
netcdf4
thin
parentheses
sage-one
slickedit
worker-thread
gcsfuse
titanium-android
specrun
migradoc
heidisql
gridpane
probability-density
google-web-starter-kit
contact-list
pagedlist
qcustomplot
ready-api
qgraphicsview
wapiti
ora-00900
django-unittest
content-length
iis-arr
drawbitmap
pretty-print
operator-precedence
ng-animate
phalanger
flask-cors
xojo
openexr
seaside
cloud-connect
centos5
terminal-services
ivyde
blending
ruby-datamapper
eclipse-memory-analyzer
sabredav
dice
buildr
libc++
window-management
floating
nintendo-ds
mtj
caching-application-block





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