Skip to content
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

Use MessageSource to interpolate bean validation messages #17530

Closed
wants to merge 1 commit into from

Conversation

nosan
Copy link
Contributor

@nosan nosan commented Jul 16, 2019

see gh-3071

Limitation

MessageSourceInterpolatorDelegate does not support \ escape character. The escape character is not supported because there is no way to configurePropertyPlaceholderHelper with it.
Is it possible to add escape support in Spring Framework?

Thanks

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 16, 2019
@philwebb philwebb added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 24, 2019
@philwebb philwebb added this to the 2.2.x milestone Jul 24, 2019
@philwebb
Copy link
Member

I've raise spring-projects/spring-framework#23348 to look at extending PropertyPlaceholderHelper

@philwebb philwebb added the status: blocked An issue that's blocked on an external project change label Jul 24, 2019
@nosan
Copy link
Contributor Author

nosan commented Jul 24, 2019

Thanks, @philwebb !

@wilkinsona wilkinsona changed the title Provide a way to to interpolate message for JSR-303 validation. Provide a way to interpolate message for JSR-303 validation. Sep 4, 2019
@snicoll snicoll modified the milestones: 2.2.x, 2.x Sep 9, 2019
@nosan
Copy link
Contributor Author

nosan commented Nov 19, 2019

Hi @philwebb,

I did some research related to this issue, and my idea to use PropertyPlaceholderHelper was doomed initially.

I thought if PropertyPlaceholderHelper had escape support it would be possible to
resolve parameters via MessageSource, but it is not possible because Bean Validation Specification
has quite a specific behavior of interpolating messages and of course, PropertyPlaceholderHelper would not be able to support such behavior.

I made a comparison between Bean Validation and Apache StringSubstitutor, and of course, they have different behavior and most probably PropertyPlaceholderHelper would have something different.

Message Template Bean Validation (Hibernate) Apache StringSubstitutor Bean Validation (org.apache.bval)
{message} must be false must be false must be false
{{message}} {{message}} {{message}} {must be false}
\\{message} \must be false \{message} \must be false
\{message} \{message} {message} {message}
{message\} {message\} {message\} {message}
\{message\} {message} {message\} {message}

I think spring-projects/spring-framework#23348 should be closed, as it would not help us here.

UPDATE:

It is recommended that MessageInterpolator implementations delegate final interpolation to the Bean Validation default MessageInterpolator to ensure standard Bean Validation interpolation rules are followed.

It means that MessageSourceInterpolatorDelegate should not resolve any escape symbols and have to replace only message parameters where it is possible.

@nosan nosan force-pushed the gh-3071 branch 3 times, most recently from e717e0b to 9ca77f9 Compare November 20, 2019 20:31
@nosan
Copy link
Contributor Author

nosan commented Nov 20, 2019

PR has been updated and ready for the review.
Thanks in advance!

@nosan nosan changed the title Provide a way to interpolate message for JSR-303 validation. Provide a way to interpolate message for JSR-303 validation Jan 7, 2020
@wilkinsona wilkinsona removed the status: blocked An issue that's blocked on an external project change label Jun 14, 2021
@wilkinsona wilkinsona changed the title Provide a way to interpolate message for JSR-303 validation Use MessageSource to interpolate bean validation messages Jul 21, 2021
@wilkinsona wilkinsona self-assigned this Jul 21, 2021
@wilkinsona wilkinsona modified the milestones: 2.x, 2.6.0-M2 Jul 26, 2021
@wilkinsona
Copy link
Member

Thanks very much, @nosan, both for the PR and for your patience while we found time to process it.

@nosan
Copy link
Contributor Author

nosan commented Jul 26, 2021

No problem at all @wilkinsona
Thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants