users@jersey.java.net

[Jersey] Re: Bean Validation Oddity

From: Robert DiFalco <robert.difalco_at_gmail.com>
Date: Tue, 18 Mar 2014 17:49:33 -0700

I wonder if it is possible to have a special implementation of the bean
validation for Jersey that would take the names from QueryParams or
PathParams when they are available. I'll dig around a bit when I get past
my current deadlines.


On Tue, Mar 18, 2014 at 1:12 PM, Ted M. Young [@jitterted] <
tedyoung_at_gmail.com> wrote:

>
> On Tue, Mar 18, 2014 at 12:23 PM, Robert DiFalco <robert.difalco_at_gmail.com
> > wrote:
>
>> Pretty much every where else I use Bean Validation it is smart enough to
>> use the name of the argument as "emailAddress".
>
>
>
> This is because Java stores (in the class files) the name of fields (the
> likely "every where else" to which you refer), but parameters' names are
> not saved (though in Java 8 this is possible[1]). That's why the
> @QueryParam, and other parameter annotations, require a String so that they
> can have a name. The arg1 comes from the standard implementation of bean
> validation[2].
>
> An alternative would be to put the email/password into, say, a User
> object, which itself would have the validation annotations on it, and that
> would provide you with names. Other than that, I'm not sure what else you
> can do other than do the null-checking "manually" in your delete method.
>
> [1]
> http://docs.oracle.com/javase/tutorial/reflect/member/methodparameterreflection.html
> [2] http://beanvalidation.org/proposals/BVAL-241/#naming
>
>
> ;ted
> --
> http://about.me/tedmyoung
>
>