0

I'd like to validate jersey parameters with a validator framework. For example I'd like to check that a parameter is not null, or not empty.

4

1 回答 1

1

Yes, it is possible.

You can use any JSR-303 implementation (like Hibernate Validator).

If you use Hibernate to persist your entities, then its very easy. Just add Hibernate validator to your classpath, and Hibernate automatically takes care of it. This would validate entities on the Data Access level.

If you want to validate entites on the serialization level (I assume this is what you want from your question), you can do one of two things:

  • Write a JAX-RS MessageBodyReader and MessageBodyWriter that validates method parameters and returned entites. See this blog post for some hints.
  • Explicitly and directly validate your entities in your JAX-RS methods.

Of course, any of these 3 solutions only take effect after your properly annotate your entities with Bean Validation Annotations.

于 2013-01-08T15:16:32.320 回答