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

后端 未结 20 1872
夕颜
夕颜 2020-11-30 00:04

With this code

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

        Foo model;
        ...         


        
相关标签:
20条回答
  • 2020-11-30 00:40

    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

    0 讨论(0)
  • 2020-11-30 00:42

    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.

    0 讨论(0)
  • 2020-11-30 00:42

    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
    
    0 讨论(0)
  • 2020-11-30 00:45

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

    0 讨论(0)
  • 2020-11-30 00:48

    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!

    0 讨论(0)
  • 2020-11-30 00:49

    The problem was that one of the nested objects in Foo didn't have any getter/setter

    0 讨论(0)
提交回复
热议问题