With this code
@RequestMapping(value = \"/bar/foo\", method = RequestMethod.GET)
public ResponseEntity foo() {
Foo model;
...
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 also experienced such error when by accident put two @JsonProperty("some_value") identical lines on different properties inside the class
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>
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>
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.
you didn't have any getter/setter methods.