Like in trying-to-use-spring-boot-rest-to-read-json-string-from-post I want to read a json payload from a POST request in a Spring RestController. Using the content type "text/plain" there is no problem, but with "application/json" the deserialization fails and I get a MessageNotReadable exception. But actually the content couldn't be simpler, it is just an empty json object "{}". Could it be that a required converter is missing? I use Spring Root version 1.2.3.RELEASE.
Coding Example
@RequestMapping(value = "/deepdefinitions", method = POST, headers = "Accept=application/json")
@ResponseBody
public Definitions createOrUpdateDefinitions(HttpEntity<String> httpEntity) throws IOException { ... }
Curl Call
curl -H "Content-type: application/json" -X POST -d '{}' http://localhost:8080/deepdefinitions
Error
{"timestamp":1434397457853,"status":400,"error":"Bad Request","exception":"org.springframework.http.converter.HttpMessageNotReadableException","message":"Could not read JSON: Can not deserialize instance of java.lang.String out of START_OBJECT token\n at [Source: org.apache.catalina.connector.CoyoteInputStream@122f9ce3; line: 1, column: 1]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token\n at [Source: org.apache.catalina.connector.CoyoteInputStream@122f9ce3; line: 1, column: 1]","path":"/deepdefinitions"}