-
Notifications
You must be signed in to change notification settings - Fork 41.1k
Improve MessageSourceMessageInterpolator when using MessageSource.setUseCodeAsDefaultMessage(true) and Bean Validation attributes #42782
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
main...nosan:spring-boot:gh-42782 contains a potential fix. |
This could introduce a breaking change. For example, if someone has a property like |
Thanks for your patience while we found time to look at this, @nosan. As far as I can remember, we haven't seen any issues about this not quite working correctly. As such, I think we should be cautious in what we change. My feeling is that it makes sense to fix If you agree, would you like to open a PR? |
Thanks @wilkinsona
Indeed, it is risky.
|
When I was doing research for #42773, I came across two potential improvements for
MessageSourceMessageInterpolator
:MessageSource.setUseCodeAsDefaultMessage(true)
Hibernate validation messages broken in spring boot 2.6.1 when setUseCodeAsDefaultMessage set to true #28930 could beimproved a little bit:
If
MessageSource
contains the searched parameter, it should be used, even if the value is identical to the parameter itself.The solution for this is quite straightforward
${validatedValue}
and for Bean Validationattributes such as
{max}
could be skipped. For example:size.person.name=${validatedValue} must be between {min} and {max}
. Currently,MessageSourceMessageInterpolator
tries to resolve {validatedValue}, {min} and {max} viaMessageSource
. Clearly, the first one is an EL expression, while the latter two are Bean Validation attributes.EL expression can be handled by:
Bean validation attributes:
UPDATE: I changed the initial description to make it clearer.
The text was updated successfully, but these errors were encountered: