custom-message-interpolation
custom-message-interpolation
Custom message interpolation
it is possible to plug in a custom MessageInterpolator implementation.
- Custom interpolators must implement the interface
jakarta.validation.MessageInterpolator - implementations must be thread-safe
- it is recommended that custom message interpolators delegate final implementation to the default interpolator, which can be obtained via
Configuration#getDefaultMessageInterpolator() - to use a custom message interpolator it must be registered either by configuring it in the Jakarta Validation XML descriptor
META-INF/validation.xmlor by passing it when bootstrapping aValidatorFactoryorValidator
ResourceBundleLocator
want to retrieve error messages from other resource bundles than ValidationMessages
in this situation Hibernate Validator’s ResourceBundleLocator SPI can help.
SPI: Service Provider Interface
- the default message interpolator in Hibernate Validator is
ResourceBundleMessageInterpolator - using an alternative bundle only requires passing an instance of
PlatformResourceBundleLocatorwith the bundle name when bootstrapping theValidatorFactory - you can implement a completely different
ResourceBundleLocator
This post is licensed under CC BY 4.0 by the author.