61

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

@RequestMapping(value = "/mobile/getcomp", method = RequestMethod.GET)
@ResponseBody
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 -->
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>${jackson.version}</version>
    </dependency>

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(Assert.java:68)
        at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:124)

Link to the example I'm following.

4
  • can you post your spring configuration plz ? Commented Oct 2, 2015 at 11:13
  • @RafikBELDI mate every thing is fine is spring config not able to add too much code in question as it demands description. Commented Oct 2, 2015 at 11:27
  • 11
    My problem was that all getters was private. Commented Feb 28, 2016 at 7:34
  • Thanks, @peter . My getters were package-private, but they needed to be public. Commented Jan 10, 2017 at 16:34

8 Answers 8

111

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.

Sign up to request clarification or add additional context in comments.

7 Comments

Adding just the getter was sufficient.
This is the correct answer. One should not add more dependencies.
Thanks the same worked for me. But little surprised how that really matters.
Worked for me. In my case setting field access to public worked as well.
yes this works. Spring should fix that error to be more specific.
|
106

Add the below dependency to your pom.xml:

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.5.0</version>
</dependency>

13 Comments

made my day, just spent more the 4 hours and no one has even mentioned this any where.
Adding the dependencies was the key for me! Thanks!
The dependecies was the key for me too. I wonder why don't they write them down in Spring's page howto: docs.spring.io/spring-boot/docs/current/reference/html/…
worked for me too! A little note for users passing by and always choose to use the last version of the dependency instead of the mentioned here. DO NOT USE THE LAST VERSION for jackson dependecy! I've tried with 2.7.0-rc1 and didn't work. With 2.6.3 worked just fine.
This isn't the case with spring4.x. Only adding getter/setters is enough.
|
12

You also need to be sure that returned bean is not empty (and can be serialized by Jackson). In my particular case I tried to return an instance of an object without getters and setters and without any jackson annotation and with fields equals to null. I got following message:

com.fasterxml.jackson.databind.JsonMappingException:
    No serializer found for class com.foo.bar.Baz and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) )

1 Comment

This is more a comment (not an answer).
8

When I was facing this issue, I simply put just getter setter methods and my issues were resolved.

I am using Spring boot version 2.0.

1 Comment

adding getter & setter will now fix the issue in this case
5

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

<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>

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

Original answer that helped me is here: https://stackoverflow.com/a/33896080/3014866

Comments

4

Yes just add the setters/getters with public modifier ;)

Comments

3

I was using groovy+springboot and got this error.

Adding getter/setter is enough if we are using below dependency.

implementation 'org.springframework.boot:spring-boot-starter-web'

As Jackson core classes come with it.

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.