dev@jersey.java.net

Re: Support for jsr303 in jersey-server

From: Tatu Saloranta <cowtowncoder_at_yahoo.com>
Date: Wed, 17 Nov 2010 10:53:34 -0800 (PST)

I think it should be easy to wire JSR-303 impl with a MessageBodyReader (or writer), if you want automatic support? Implementation can extend an existing reader to get data binding piece, then call validator.

I have usually just done explicit call from method after data binding; it's a simple one-liner. So while more integrated supported could be nice, I don't think this is very hard to do without framework-level support.

-+ Tatu +-

--- On Tue, 11/16/10, Nicolas Griso <nicolas.griso_at_gmail.com> wrote:

> From: Nicolas Griso <nicolas.griso_at_gmail.com>
> Subject: Re: Support for jsr303 in jersey-server
> To: dev_at_jersey.dev.java.net
> Date: Tuesday, November 16, 2010, 2:39 PM
> Hi,
>
> Seems that I'll have to wait for jax-rs 2.0 implementation:
> (from
> http://markmail.org/message/wgm3hj3rrva3j6jo?q=list:net.java.dev.jsr311.dev#query:list%3Anet.java.dev.jsr311.dev+page:1+mid:wgm3hj3rrva3j6jo+state:results)
> "JAX-RS 1.1 has limited support for parameter validation.
> This JSR
> will make it possible to validate a set of parameters, such
> as form or
> query parameters, and to return a meaningful response in
> case
> validation fails. The primary API utilized for validation
> will be the
> Bean Validation API. "
>
> Regards,
> Nicolas Griso
>
> On Thu, Nov 11, 2010 at 3:45 PM, Nicolas Griso <nicolas.griso_at_gmail.com>
> wrote:
> > Hello,
> >
> > I'd like to know if there is in jersey-server a
> support for javabean
> > validation (jsr 303) for method receiving data in
> Resource classes?
> > (I searched but I haven't found anything)
> >
> > For example, Spring MVC is supporting something like
> this:
> > @Controller
> > public class MyController {
> >    @RequestMapping("/foo",
> method=RequestMethod.POST)
> >    public void processFoo(@Valid Foo foo) { /* ...
> */ }
> >
> > Example from: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/validation.html#validation-mvc
> > Method parameters can be annotated with @Valid
> (annotation from the
> > jsr303) which makes Spring validated the data before
> calling the
> > method.
> >
> > What do you think of this?
> > Can something similar be implemented in
> jersey-server?
> >
> > Thanks a lot.
> > Nicolas Griso
> >
>