[java] java.lang.IllegalArgumentException: No converter found for return value of type

With this code

@RequestMapping(value = "/bar/foo", method = RequestMethod.GET)
    public ResponseEntity<foo> foo() {

        Foo model;
        ...
        return ResponseEntity.ok(model);
    }
}

I get the following exception

java.lang.IllegalArgumentException: No converter found for return value of type

My guess is that the object cannot be converted to JSON because Jackson is missing. I don't understand why because I thought that Jackson was built in with spring boot.

Then I have tried to add Jackson to the pom.xml but I still have the same error

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

Do I have to change any spring boot properties to make this work?

Thank you

This question is related to java spring spring-boot jackson

The answer is


In my case, I forgot to add library jackson-core.jar, I only added jackson-annotations.jar and jackson-databind.jar. When I added jackson-core.jar, it fixed the problem.


Use @ResponseBody and getter/setter. Hope it will solve your issue.

@RequestMapping(value = "/bar/foo", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<foo> foo() {

and update your mvc-dispatcher-servlet.xml:

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

While using Spring Boot 2.2 I run into a similiar error message and while googling my error message

No converter for [class java.util.ArrayList] with preset Content-Type 'null'

this question here is on top, but all answers here did not work for me, so I think it's a good idea to add the answer I found myself:

I had to add the following dependencies to the pom.xml:

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-oxm</artifactId>
</dependency>

<dependency>
  <groupId>com.thoughtworks.xstream</groupId>
  <artifactId>xstream</artifactId>
  <version>1.4.11.1</version>
</dependency>

After this I need to add the following to the WebApplication class:

@SpringBootApplication
public class WebApplication
 {
  // ...

  @Bean
  public HttpMessageConverter<Object> createXmlHttpMessageConverter()
   {
    final MarshallingHttpMessageConverter xmlConverter = new MarshallingHttpMessageConverter();
    final XStreamMarshaller xstreamMarshaller = new XStreamMarshaller();
    xstreamMarshaller.setAutodetectAnnotations(true);
    xmlConverter.setMarshaller(xstreamMarshaller);
    xmlConverter.setUnmarshaller(xstreamMarshaller);
    return xmlConverter;
   }

}

Last but not least within my @Controller I used:

@GetMapping(produces = {MediaType.APPLICATION_XML_VALUE, MediaType. APPLICATION_JSON_VALUE})
@ResponseBody
public List<MeterTypeEntity> listXmlJson(final Model model)
 {
  return this.service.list();
 }

So now I got JSON and XML return values depending on the requests Accept header.

To make the XML output more readable (remove the complete package name from tag names) you could also add @XStreamAlias the following to your entity class:

@Table("ExampleTypes")
@XStreamAlias("ExampleType")
public class ExampleTypeEntity
 {
  // ...
 }

Hopefully this will help others with the same problem.


In my case i'm using spring boot , and i have encountered a similar error :

No converter for [class java.util.ArrayList] with preset Content-Type 'null'

turns out that i have a controller with

@GetMapping(produces = { "application/xml", "application/json" })

and shamefully i wasn't adding the Accept header to my requests


The issue occurred in my case because spring framework couldn't fetch the properties of nested objects. Getters/Setters is one way of solving. Making the properties public is another quick and dirty solution to validate if this is indeed the problem.


The answer written by @Marc is also valid. But the concrete answer is the Getter method is required. You don't even need a Setter.


I had the very same problem, and unfortunately it could not be solved by adding getter methods, or adding jackson dependencies.

I then looked at Official Spring Guide, and followed their example as given here - https://spring.io/guides/gs/actuator-service/ - where the example also shows the conversion of returned object to JSON format.

I then again made my own project, with the difference that this time I also added the dependencies and build plugins that's present in the pom.xml file of the Official Spring Guide example I mentioned above.

The modified dependencies and build part of XML file looks like this!

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

You can see the same in the mentioned link above.

And magically, atleast for me, it works. So, if you have already exhausted your other options, you might want to try this out, as was the case with me.

Just a side note, it didn't work for me when I added the dependencies in my previous project and did Maven install and update project stuff. So, I had to again make my project from scratch. I didn't bother much about it as mine is an example project, but you might want to look for that too!


I saw the same error when the scope of the jackson-databind dependency had been set to test:

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.9.9</version>
    <scope>test</scope>
</dependency>

Removing the <scope> line fixed the issue.


I faced the same problem but I was using Lombok and my UploadFileResponse pojo was a builder.

public ResponseEntity<UploadFileResponse> 

To solve I added @Getter annotation:

@Builder
@NoArgsConstructor
@AllArgsConstructor
@Getter
public class UploadFileResponse

you didn't have any getter/setter methods.


Faced same error recently - the pojo had getters/setters and all jackson dependencies were imported in pom correctly but some how "< scope > " was "provided" for jackson dependency and this caused the issue. Removing " < Scope > " from jackson dependency fixed the issue


In my case, I was returning Boolean in Response Entity and had :

produces = MediaType.TEXT_PLAIN_VALUE,

When i changed it to below

produces = MediaType.APPLICATION_JSON_VALUE

It worked!

Example of what i had.

@PostMapping(value = "/xxx-xxxx",
            produces = MediaType.APPLICATION_JSON_VALUE,
            consumes = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<Boolean> yyyy(

@EnableWebMvc annotation on config class resolved my problem. (Spring 5, no web.xml, initialized by AbstractAnnotationConfigDispatcherServletInitializer)


I also experienced such error when by accident put two @JsonProperty("some_value") identical lines on different properties inside the class


I was facing same issue for long time then comes to know have to convert object into JSON using Object Mapper and pass it as JSON Object

@RequestMapping(value = "/getTags", method = RequestMethod.GET)
public @ResponseBody String getTags(@RequestParam String tagName) throws
        JsonGenerationException, JsonMappingException, IOException {
    List<Tag> result = new ArrayList<Tag>();
    for (Tag tag : data) {
        if (tag.getTagName().contains(tagName)) {
            result.add(tag);
        }
    }
    ObjectMapper objectMapper = new ObjectMapper();
    String json = objectMapper.writeValueAsString(result);
    return json;
}

Add below dependency in pom.xml:

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.10.1</version>
    </dependency>

Was facing the same issue as the return type cannot be bind with the MediaType of Class Foo. After adding the dependency it worked.


Add the below dependency to your pom.xml:

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

I was getting the same error for a while.I had verify getter methods were available for all properties.Still was getting the same error. To resolve an issue Configure MVC xml(configuration) with

 <mvc:annotation-driven/>

.This is required for Spring to detect the presence of jackson and setup the corresponding converters.


Add the getter/setter missing inside the bean mentioned in the error message.


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to spring

Are all Spring Framework Java Configuration injection examples buggy? Two Page Login with Spring Security 3.2.x Access blocked by CORS policy: Response to preflight request doesn't pass access control check Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified Spring Data JPA findOne() change to Optional how to use this? After Spring Boot 2.0 migration: jdbcUrl is required with driverClassName The type WebMvcConfigurerAdapter is deprecated No converter found capable of converting from type to type

Examples related to spring-boot

Access blocked by CORS policy: Response to preflight request doesn't pass access control check Why am I getting Unknown error in line 1 of pom.xml? Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured How to resolve Unable to load authentication plugin 'caching_sha2_password' issue ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified After Spring Boot 2.0 migration: jdbcUrl is required with driverClassName ERROR Source option 1.5 is no longer supported. Use 1.6 or later How to start up spring-boot application via command line? JSON parse error: Can not construct instance of java.time.LocalDate: no String-argument constructor/factory method to deserialize from String value

Examples related to jackson

No Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator JSON parse error: Can not construct instance of java.time.LocalDate: no String-argument constructor/factory method to deserialize from String value How to convert JSON string into List of Java object? Deserialize Java 8 LocalDateTime with JacksonMapper java.lang.IllegalArgumentException: No converter found for return value of type java.lang.ClassNotFoundException: com.fasterxml.jackson.annotation.JsonInclude$Value How to modify JsonNode in Java? Deserialize JSON with Jackson into Polymorphic Types - A Complete Example is giving me a compile error Convert Map to JSON using Jackson Required request body content is missing: org.springframework.web.method.HandlerMethod$HandlerMethodParameter