0

I have a hibernate-validation message that interpolates a value ${value}.

Issue is, that the value variable itself is a string of the form "${ohno}". I'd like my final interpolated message to replace ${value} with this literal string "${ohno}" but instead it seems to attempt some sort of recursive interpolation which produces the error "Cannot find property ohno".

I can't really thing of a way to "escape" this string in the message template. Perhaps I can escape it in the string itself before I pass it to the annotation but I'd rather not have to do that (I use this string as a literal elsewhere).

Does anyone know of a work around? Or perhaps I should open up a ticket with hibernate-validator...

1 Answer 1

1

There is really no work around except escaping {,},\ and $ are meta characters which need to be escaped in Bean Validation. See Message Interpolation in the spec. See also HV-934 in the Validator issue tracker.

Now, if you really do not want to interpolate according to the Bean Validation specification, you can write your on MessageInterpolator and make sure that it gets picked up during Validator initialization. Basically you need a validation.xml pointing out your custom interpolator. Check the docs, there are several examples how to do it.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Hardy. I was the one that actually created that ticket and responded there. I guess I don't have much choice. A custom MessageInterpolator might be overkill for me so I'll just try to escape the string.
I actually found a work around. In the message, rather than using {value} I used ${true? value: ''}. Hacky, but it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.