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...

kennyg
  • 999
  • 2
  • 10
  • 23

1 Answers1

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.

Hardy
  • 18,659
  • 3
  • 49
  • 65
  • 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. – kennyg Sep 29 '14 at 14:12
  • I actually found a work around. In the message, rather than using {value} I used ${true? value: ''}. Hacky, but it works. – kennyg Sep 30 '14 at 18:59