I'm getting an error (Handler execution resulted in exception: Content type 'application/json' not supported) when trying to receive a post request using Spring MVC.
My Json, just for testing, is pretty simple:
{ "test": "abc123" }
My pojo class:
public class Request {
String test;
public String getTest() {
return test;
}
public void setTest(String test) {
this.test = test;
}
}
And my controller:
@RequestMapping(value = "/testing", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
private void testing(@RequestBody Request body, @RequestHeader HttpHeaders headers, HttpServletRequest httpRequest) {
System.out.println(body.getTest());
}
In my pom.xml, I added:
<dependencies>
...
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.8.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.4.3</version>
</dependency>
</dependencies>
I think that something is wrong in json deserialization, but I cannot find it.
Any help is welcome. Thanks.
In my case the problem was an addition to a dto of a property which having a type that was error prone for Jackson, it was of type JsonObject. Jackson was unable to deserialize other objects because of that addition.
The exception message is completely inaccurate!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With