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

Implementation of Kallmann's Dynamic Constrained Delaunay Triangulation algorithm [closed]
Apply FFT to audio recording in java
Access LinearLayout Subclass Parameter from Button Click
Fill annotation parameter value with value from properties file
Java, How do i use add a string and an integer to an array
Android inflate exception - ViewPager
Object ob; and Object ob = new Object; [closed]
Is Java's equality operator commutative?
Java: How to compare if statement with object?
Adding a cookie to my HTML page?
Nested listeners that use notify-method with the same name
How to create two pages in report with same content
Shiro Configuration for testing a JSP web app
How to generate 4 unduplicated numbers from certain range?
Java Sell Method Stock Class
Is there a way to check all the components name in java using a loop?

Categories

HOME
listview
android-4.4-kitkat
youtube-dl
q
react-redux
amazon-ecs
electronics
umd
wamp
etl
windows-phone-7
workload-scheduler
after-effects
ef-migrations
ab-testing
swingx
ml
riot.js
scriptcs
web-sql
kvc
bootstrap-tour
captiveportal
tooltipster
fluentvalidation
typo3-6.2.x
replaceall
ecto
uisplitview
exuberant-ctags
subset-sum
android-kernel
bytecode-manipulation
simplexml
bitbucket-pipelines
xcode-extension
swift3.0.2
mixture-model
abstract-class
az-application-insights
azure-ml
sfdc
pdf-reactor
gulp-sourcemaps
keydown
galleria
xml-documentation
jedis
pubmed
statsd
font-size
topbeat
parallel-data-warehouse
radtreelist
angstrom-linux
design-by-contract
vhd
quicklisp
php-ci
composite
sonarqube5.1.2
pretty-print
project-planning
rebol3
marmalade
dealloc
srs
farseer
access-rights
web2py-modules
tws
eventlistener
tinn-r
mhtml
path-separator
manchester-syntax
newtonscript
gnustep
tomcat-valve
self-extracting
ecl
fluent-interface
asp.net-mvc-areas
wise
icanhaz.js
vc90
perfect-hash
thread-local-storage
procedural-music
mdac
paul-graham

Resources

Encrypt Message