Victor Mezrin
Victor Mezrin

Reputation: 2837

JAX-RS ignores bean validation constraints

I made a JAX-RS service. It consumes/produces json via POST requests. Everything works fine except bean validation

I added some constraints from package javax.validation.constraints to the fields of my POJOs, that are used as wrappers for request/response messages. (POJOs does not have any other annotations like JAXB @XmlRootElement or smth else)

If I try to call my service - it works, but constraints ignored completely. I.e. I call my service using right or wrong parameters and calls passed RAX-RS layer to my EJB in both cases.

What could I miss? Some special config, some special dependencies?

P.S. I use glassfish 4.0 with provided Jersey 2.0

Upvotes: 1

Views: 598

Answers (1)

gregwhitaker
gregwhitaker

Reputation: 13420

In order for bean validation to be invoked you need to have a validator on your classpath. A commonly used validator is the hibernate-validator as it is the reference implementation.

http://www.hibernate.org/subprojects/validator.html

Once you have the validator on the classpath it will be detected and invoked when JSR-303 annotations are encountered.

Upvotes: 1

Related Questions