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

ConcurrentModificationError - but no modifications?
How to deserialize different subtypes with generics with one gson deserializer
I am working with expandable list view and couldn't access content of list view from textview(changing TextView to String)?
How to create an ArrayList for every unique column value of a .txt file in Java?
Check statement for every list item
Java Date toString in different format after loaded from database
Query using running total in hibernate
ORA-29481: Implicit results cannot be returned to client when calling Oracle 12c procedure from JDBC
How to mask last parentheses brackets in string using java replaceAll(regex, replacement) method?
Create a Google Group programtically with Google Admin SDK [duplicate]
Typecast to List using a Class type variable java [duplicate]
Correct Maven Dependency for Spark API
How do I extract the specific date out in Java? [duplicate]
Trouble printing table of results
Beginner Java: Simple grade average code
Unable to break out of a while loop. [duplicate]

Categories

HOME
google-chrome-extension
hook
blogger
pypi
debugging
urbancode
tinymce
sqlite-net-extensions
maven-3
yarn
baqend
cross-browser
in-app-purchase
swagger-ui
append
izpack
php-7.1
systemc
openrefine
sms-gateway
crystal-reports-2008
facebook-instant-articles
google-search-api
cultureinfo
dxf
javacv
apache-commons-io
maquette
gsoap
nameservers
exuberant-ctags
noraui
atl
html5-fullscreen
host
streamsets
reportbuilder
ws-security
sql-server-agent
keydown
mime
bootstrap-dialog
sencha-touch-2.3
typescript1.8
gabor-filter
composite-key
akka-cluster
sts-springsourcetoolsuite
trash
player
firebaseui
superstack
make-install
php-parse-error
jfugue
rtbkit
responsive-images
sysinternals
fluid-dynamics
umbraco6
kineticjs
knuth
qcodo
preferences
dml
rebol3
doskey
mysql-error-1062
mechanize-ruby
terminal-services
spring-validator
mhtml
browser-detection
jquery-knob
path-separator
wse3.0
dotnethighcharts
semantic-diff
rfc1123
recent-documents
pyinotify
subviews
nsviewanimation
vc90
user-friendly
sustainable-pace
putchar
ubuntu-9.04
3gp
rtml

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