StaxMan
StaxMan

Reputation: 116580

Can Hibernate Validator be used as component outside Hibernate?

I am trying to add validation for message payload (which are json). I am using Jackson Json processor for data binding, which works quite well for me, using bean methods and occasional annotation or two.

But beyond data binding, I would like to declaratively validate actual values: and specifically I prefer annotations over any external schema (DRY principle, keeping code & constraints fully in-sync). And so I am looking for a simple validation library to do this.

It looks like JSR-303 pretty much defines annotations I would need for declaration part. And it looks like Hibernate Validator is an implementation for actual validator that uses these annotations. But documentation covers use case where it is used with Hibernate, so I am not sure if it could be used outside Hibernate itself. Since I do not do any database access for the service in question, I would prefer not including other parts of Hibernate.

Has anyone done this or have good pointers to samples?

Alternatively, if anyone knows of another good JSR-303 implementation that would work as well.

Upvotes: 4

Views: 1141

Answers (1)

Jerrish Varghese
Jerrish Varghese

Reputation: 581

Hibernate Validator can be used at any layers. However automatic validation will not happen in your case. So you have to trigger the validation programmatically.

Upvotes: 4

Related Questions