In the ExceptionHandler
for MethodArgumentNotValidExceptions
a way for getting the serialized names of the violated fields is missing. Using MethodArgumentNotValidException.getBindingResult().getAllErrors()
... FieldError.getField()
the POJO's name is returned which is not acceptable for the response body in case of different serialized names (Example: photoUrls
vs. photo-urls
).
Code:
@JsonProperty("photo-urls")
private List<URL> photoUrls;
In this case photoUrls
is returned which is the wrong key for the client's request.
Comment From: wilkinsona
Thanks for the suggestion. As with https://github.com/spring-projects/spring-boot/issues/25104, this issue really belongs in Spring Framework. We'll transfer the issue over to them. You can identify enhancements that belong in the Spring Boot project by their code's package. All Spring Boot code is in an org.springframework.boot
package or sub-package.
Comment From: bclozel
See #26507
Comment From: snicoll
I am not sure I get the link with @JsonProperty
. This is a Jackson-specific hint and the validation happens on the POJO, not on the content of the JSON object. Besides FieldError
is pretty specific.
This seems to me that these are two layers of responsibility that should be separate. Thoughts?
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: spring-projects-issues
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.