If an object is missing a @JsonProperty annotation on a parameter to a @JsonCreator-annotated constructor or factory, for some reason the returned error is 415 (instead of maybe a 400 or 500?). This can be extremely confusing, because controllers may be explicitly listed as supporting the given media type (and makes things weirder since the returned media type may be the same as the type sent).
Note that Jackson does log the actual problem:
2018-01-24 16:40:48.873 WARN 49180 --- [nio-8080-exec-2] .c.j.MappingJackson2HttpMessageConverter : Failed to evaluate Jackson deserialization for type [[simple type, class hello.Greeting]]: com.fasterxml.jackson.databind.JsonMappingException: Argument #0 of constructor [constructor for hello.Greeting, annotations: {interface com.fasterxml.jackson.annotation.JsonCreator=@com.fasterxml.jackson.annotation.JsonCreator(mode=DEFAULT)}] has no property name annotation; must have name when multiple-parameter constructor annotated as Creator
...however, this may be hard to miss, and is especially troublesome to find when dealing with automated tests, as they will report an exception on the return content type.
Minimal project: repro.zip
Start it up and then POST to 8080/greeting with something like:
{
"id": "1",
"content": "hello"
}
Comment From: wilkinsona
Thanks for the sample. The logic that deals with this is part of Spring Framework. I agree that a 415 is rather confusing in this case but I’m not sure what can be done about it. If you would like to pursue it, please open a JIRA and comment here with a link to it.
Comment From: bclozel
This is Spring Framework trying to warn you about (de)serialization issues (Jackson does not log anything here). Because we can't tell for sure why Jackson cannot convert JSON here - Spring might be trying to use JSON as format here as a last resort - HTTP 415 has been chosen as the lest surprising status; See SPR-15582.
Comment From: nisarusan
I have a similair error, that I can't fix as study project. Been hours busy with it, can't fix it