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

JPA Inheritance TABLE_PER_CLASS throws MappableContainerException
Android Marshmallow 6.0.1 broke my continuous speech recognition
How to determine the type of “Fragment” object that is passed
BMC remedy user tool through java
Getting log4j error while running data driven testing code
How to cancel onGoing notification?
swagger bug missing model package
Stream groupingBy values
Verifying Signature in Smart Card
How to read a String more than 1 character at a time
Reading the contents of a text file [duplicate]
Spring Web Services 2.2.5 in Jboss 5.1.0 GA
jackson: how to unmarshal to a class using generics in runtime?
How to set Tab width in Tab layout?
Sybase throws Exception “there is already another cursor with the name XXX” when Executing SELECT Query in multi-threading environment
SSO Spring Security and JSF

Categories

HOME
winforms
multithreading
json.net
hashmap
twitter-bootstrap-4
binary-tree
retrofit
azure-storage-tables
webrequest
esper
nstableview
hex-editors
visual-studio-cordova
zebra-printers
iron-router
try-catch
netflix
serilog
oracle-coherence
nhibernate-envers
shared-hosting
lldb
introduction
emulator
immutable.js
amazonsellercentral
reverse-proxy
kryo
arabic
graphicsmagick
mmap
jndi
emgucv
facebook-access-token
xacml
large-file-upload
ecto
create-table
protovis
form-data
http-referer
overriding
http-digest
devextreme
main
hockeyapp
withings
android-browser
occlusion
unobtrusive-validation
document.write
trim
android-tabhost
nomethoderror
bootstrap-dialog
checkboxlist
google-datalayer
jsch
chain-builder
idisposable
ifs
knpmenubundle
pdfclown
smart-table
parallel-data-warehouse
url-masking
mikroc
google-web-starter-kit
storekit
packagist
dlna
itextpdf
pyke
collapse
coveralls
map-projections
php-ci
sonarqube5.1.2
inmobi
directoryservices
asp.net-dynamic-data
socketexception
xcode-6.2
device-manager
flask-cors
rtmfp
jboss-weld
gnu-smalltalk
page-layout
geos
inbox
listings
flash-builder4.5
eventual-consistency
orchardcms-1.7
limejs
lcs
html-editor
smtp-auth
typoscript2
unc
trusted
multipage
spyware
hirefire
xmlspy
invite
disclosure
user-friendly
mtj
ubuntu-9.04
signal-handling

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile