Published 01 Sep, 2022

Java - How to return JSON data from spring Controller using @ResponseBody

Category Java
Modified : Sep 29, 2022

Spring version 4.2.0, Hibernate 4.1.4 Here is my Controller function:

@RequestMapping(value = "/mobile/getcomp", method = RequestMethod.GET)
public List<Company>  listforCompanies() {      
    List<Company> listOfCompanies= new ArrayList<Company>();        
    listOfCompanies = companyManager.getAllCompanies();
    return listOfCompanies;

Jackson JSON mapper dependency in Pom.xml:

    <!-- Jackson JSON Mapper -->

Getting the list in my ArrayList, but when returning the following error is shown:

SEVERE: Servlet.service() for servlet [dispatcherServlet] in context with path [/IrApp] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.ArrayList] with root cause
    java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.ArrayList
        at org.springframework.util.Assert.isTrue(
        at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(

Link to the example I'm following.


There are 4 suggested solutions here and each one has been listed below with a detailed description. The following topics have been covered briefly such as Json, Java, Spring Mvc, Spring, Spring 4. These have been categorized in sections for a clear and precise explanation.


Add the below dependency to your pom.xml:



I was facing same issue. I did not put @ResponseBody since I was using @RestController. But still I was getting error because I did not put the getter/setter method for the Company class. So after putting the getter/setter my problem was resolved.


Considering @Arpit answer, for me it worked only when I add two jackson dependencies:


and configured, of cause, web.xml <mvc:annotation-driven/>.

Original answer that helped me is here:


In my case I was using jackson-databind-2.8.8.jar that is not compatible with JDK 1.6 I need to use so Spring wasn't loading this converter. I downgraded the version and it works now.