Dear experts,
we are working on improving integration with BeanValidation
[1], and seems like if we choose to address this issue, the
change will be slightly bigger than I anticipated.
In short, the issue is about providing Locale based on incoming
request to the BV runtime, which can then choose it to provide
localized error message. Since there is no way how to get a list
of supported locales, we'd need to introduce a provider, which
would register supported locales:
public interface SupportedLocaleProvider {
List<Locale> getSupportedLocales();
}
If the application contains @Provider annotated subclass of
this interface and there is a BV message to be produced,
implementation would be required to do something like:
SupportedLocaleProvider supportedLocaleProvider = ...;
javax.ws.rs.Request request = ...;
List<Locale> locales = supportedLocaleProvider.getSupportedLocales();
javax.ws.rs.Variant.VariantListBuilder variantListBuilder = Variant.VariantListBuilder.newInstance();
List<Variant> vs = variantListBuilder.languages(locales.toArray(new Locale[]{})).build();
Variant v = request.selectVariant(vs);
(+ null checks, etc). If selected variant exists, then
"v.getLanguage()" would be used as a Locale passed to BV
runtime.
Please let us know what do you think about proposed solution of
linked issue.
Also, the introduced interface might have more uses that just
this (maybe too specific) case - any brainstorming ideas to what
it could be used are welcomed.
Thanks and regards,
Pavel
[1] https://github.com/jax-rs/api/issues/544