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

Spring catch all response types
spring custom json message converter for controller
How to count data in Java MySQL
Multiple threads debugging in Eclipse
Java Swing - repaint() of two overlapped JPanel
Java: ArrayList of “Transaction” Objects: adding specific values
Matcher: “No match found…”
Java on ServiceBus for Windows Server- Options?
JPA entities cannot create the correct db tables
Velocity. Can't load my resources
How can I set the URL for a JSP page?
Compiled program won't System.out [duplicate]
db already exists with different case other
HashMap java, saving ADSB Messages
Android custom view not showing
Java not displaying a special UTF symbol?

Categories

HOME
wso2-am
deployment
openstack
magnific-popup
deezer
drivers
push-notification
google-play
office365api
sd-card
framework7
getelementsbytagname
rsync
jxls
gps
ip
angular-ui-bootstrap
yum
azure-media-services
offline
zend-framework3
dynamics-crm-online
django-simple-history
seaborn
transformation
code-review
django-cms
lldb
grails3
xlsxwriter
java-3d
riot.js
abi
mps
dxf
rst2pdf
greendao
web-api-testing
bcd
iframe-resizer
yadcf
grails-3.1
hybridauth
textmate
fusionpbx
wixsharp
reportbuilder
sas-visual-analytics
sql-server-agent
jvm-languages
firebase-admin
flashair
appcompat
dds
winscp-net
nstextview
elgg
forever
namecoin
synchronous
asp.net-4.5
qgraphicsview
xpath-1.0
pyke
freelancer.com-api
unity-networking
atk4
iis-arr
riak-cs
interrupted-exception
dd
camanjs
cdt
issuu
contenttype
system.net.webexception
algebraic-data-types
multiprocessor
.aspxauth
sitemesh
shellexecute
xamlparseexception
http-unit
wsdl-2.0
distutils
funscript
getmessage
appconkit
xtype
rfc1123
yui-datatable
iphone-web-app
w3wp.exe
preference
asp.net-profiles
database-management
iweb
photoshop-cs4
sustainable-pace
aquaticprime

Resources

Encrypt Message