users@jersey.java.net

Re: [Jersey] JSON Validation

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 25 Mar 2010 10:50:13 +0100

On Mar 24, 2010, at 11:38 PM, Tatu Saloranta wrote:

> On Wed, Mar 24, 2010 at 9:40 AM, Chris Carrier <ctcarrier_at_gmail.com>
> wrote:
>> I'm not very familiar with the Java bean validation stuff. I assume
>> you're referring to JSR 303 like the Hibernate Validator:
>
> Yes. I have used hibernate validator itself, which fortunately is
> light on dependencies (need not use anything from hibernate proper
> afaik).
>
>> http://docs.jboss.org/hibernate/stable/validator/reference/en/html_single/
>>
>> How does this integrate with JAX-RS/Jersey? If I annotate my POJO's
>> with Hibernate Validation annotations will they automagically be
>> validated by Jersey? Do I still have to manually add some step to
>> trigger validation? I would really like to perform validation in a
>> more standard/less obtrusive way but at this point I'm pretty much
>> using a bunch of null checks after marshalling.
>>
>> Any more info on this would be greatly appreciated.
>
> I don't think there is automatic integration (some might be nice);

Some form of integration would be nice, just not sure how do it.

It may require some use of AOP to intercept method calls.

Request filters do not know what the parameters values are since
request filters are applied before binding a request to method
parameter types.

Response filters are aware of the entity so validation could be
performed on that, given an appropriate validation context.

Paul.

> I
> just explicitly validated beans, in my cases just requests. Since I
> did explicit data binding (for more explicit logging, error handling)
> it was just one small step. Validation itself is a one-liner so it
> sort of naturally fits after reading data as object, or before writing
> object as data.
> I wish I had sample code at hand (it was done for a company, not open
> source, so I don't have exact piece to share).
>
> Paul and others may be able to suggest more generic approach (a
> filter?) to use. Actually, I wonder if one could override response
> builder to do this right before serialization gets called.
>
> -+ Tatu +-
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>