-
Notifications
You must be signed in to change notification settings - Fork 38.5k
CodecException (from JSON conversion) in RestController is not mapped to 400 but 500 (SB 2.2.5 & Kotlin) #24646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is happening also for WebMVC based projects |
I took a closer look at the problem. This seems to be the place that is responsible for this behaviour: Class AbstractJackson2Decoder SB 2.2.4
--> All JsonProcessingException are mapped to a DecodingException SB 2.2.5
--> The specialized JsonMappingException is mapped to a CodecException |
@csh0711 AbstractJackson2Decoder is a class in Spring-Framework and not in Boot itself. The issues look closely related to the following issues there:
Maybe the Boot team can transfer this in case it's a new variant of the above issues, but I guess otherwise it's gonna be fixed simply in Spring Framework. |
Thanks @dreis2211, I agree. I've moved the issue to framework for further consideration. We might close it as duplicate if it turns out to be the same problem. |
Okay, thanks @snicoll and @dreis2211 👍 |
This is indeed the same problem, just in the reactive codec implementation as opposed to the |
We just upgraded our Kotlin project from Spring Boot 2.2.4 to 2.2.5.
Unfortunately now some WebFlux-RestController tests fail because a mandatory JSON payload field now leads to a 500 Internal Server Error instead of a 400 Bad Request.
This is an exemplary RestController with its Kotlin data class for the request payload:
Please notice that attribute foo is mandatory (no
?
).This is the invalid payload (missing JSON field
foo
):{ "bar": "bar text" }
When calling this RestController in a Spring Boot 2.2.4 app this results in a DecodingException which is correctly mapped to the status code 400.
But when calling this RestController in a Spring Boot 2.2.5 app this leads to CodecException which is not mapped to the status code 400 but results in a 500.
Please find the example in my GitHub repo: https://github.com/csh0711/boot-2-2-5-kotlin-codec-exception
Or use this ControllerTest:
Many thanks in advance! :-)
The text was updated successfully, but these errors were encountered: