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

后端 未结 20 1869
夕颜
夕颜 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:35

    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.

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

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

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

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

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

    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.

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

    you didn't have any getter/setter methods.

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