users@jax-rs-spec.java.net

[jax-rs-spec users] Improving the integration of JAX-RS and Bean Validation

From: Gunnar Morling <gunnar_at_hibernate.org>
Date: Wed, 11 Jan 2017 20:13:08 +0100

Hi,

Congrats and welcome to the new spec lead!

Using that opportunity, can I make two proposals towards improving the
integration of JAX-RS with Bean Validation:

* The first is I18N of validation error messages. If nothing else is
configured, BV uses the JVM default Locale for accessing validation
message bundles. For JAX-RS it'd be great if the request locale (as
expressed via the Accept-Language header) could be used instead, if
present. Some people achieved that using some ThreadLocale hackery
[1], but mandating this behaviour in the JAX-RS spec would be much
more convenient.

* The other thing is means of disabling automatic validation of BV
constraints as part of the JAX-RS request lifecycle. That's based on a
request by Antonio Goncalves [2] and it seems reasonable to me.
Similar to the BV integration of JSF and JPA, there could be a
JAX-RS-defined property for controlling the validation behaviour,
allowing to disable it if needed, e.g. during certain kinds of
testing. It could look very similar to the property JPA defines for
that purpose:

    javax.persistence.validation.mode={auto|callback|none}

"auto" will perform validation during the entity lifecycle if a BV
provider is present. So will "callback", with the difference that it
raises an exception if no BV provider is present. "none" will disable
validation.

Do you think we could have this added these things to the JAX-RS 2.1
spec? They'd help people with using these two techs, and it should not
require too much for specifying them.

Also if there is anything we can improve on the BV side of things,
please let me know.

Looking forward to hearing from you,

--Gunnar

[1] https://jaxenter.com/integrating-bean-validation-with-jax-rs-2-106887.html
[2] https://hibernate.atlassian.net/browse/BVAL-521