users@jersey.java.net

[Jersey] Re: Bean Validation -- Activation per HTTP Method?

From: Michal Gajdos <michal.gajdos_at_oracle.com>
Date: Tue, 05 Nov 2013 22:23:53 +0100

There is nothing like this available in Jersey out of the box. Most of
the default constraint annotations are designed in a way which considers
null value as valid (for example see @Pattern, @Max). I agree that in
some cases you want to validate a field for a non-null value only for
certain HTTP methods. For these cases it seems cleaner to me to create a
separate constraint annotation with custom validator which would
validate annotated field only for desired HTTP methods (for this purpose
you can inject UriInfo into a validator instance).

(If you see a better way how to deal with situations like this, please,
file an improvement task into our JIRA)

Thanks,
Michal

On 05.11.2013, 21:42 , Miles, Eric (CONT) wrote:
> I did, nothing was there. I'm pretty good about RTFM as well as
> getting into source itself.
>
> Thanks,
>
> *Eric Miles*
>
>
> From: Marek Potociar <marek.potociar_at_oracle.com
> <mailto:marek.potociar_at_oracle.com>>
> Reply-To: Jersey Users <users_at_jersey.java.net
> <mailto:users_at_jersey.java.net>>
> Date: Tuesday, November 5, 2013 3:35 PM
> To: Jersey Users <users_at_jersey.java.net <mailto:users_at_jersey.java.net>>
> Subject: [Jersey] Re: Bean Validation -- Activation per HTTP Method?
>
> Have you checked Jersey User Guide?
> https://jersey.java.net/documentation/latest/bean-validation.html
>
> Marek
>
> On 28 Oct 2013, at 17:54, Miles, Eric (CONT)
> <Eric.Miles_at_capitalone.com <mailto:Eric.Miles_at_capitalone.com>> wrote:
>
>> This seems like it would be a fairly common issue to have to solve,
>> so I'm surprised I'm not finding much (anything really) on how to
>> apply constraints on a per HTTP method basis. I'm going to pose it
>> here and hope someone has some suggestions for me.
>>
>> Take an entity that we have constraints on, i.e. @NotNull, etc and we
>> only want to apply them on certain HTTP methods. For instance, an Id
>> field we would want to apply an @NotNull constraint to on HTTP PUT
>> but not an HTTP POST. Or maybe the same entity that is used as a
>> @BeanParam and we'd want the name field (also annotated with
>> @QueryParam) to be @NotNull for POST and PUT but not for GET.
>>
>> My original thought was to use groups but after some long hard looks
>> at the bean validation spec I don't think that's going to be the way
>> to go. Anything "out of the box" for this kind of support in jersey?
>> Any other ideas? This seems like more of a Jersey item than a JSR
>> 349 item, thus the post here.
>>
>> Thanks in advance.
>>
>> Eric
>>
>> ------------------------------------------------------------------------
>> The information contained in this e-mail is confidential and/or
>> proprietary to Capital One and/or its affiliates. The information
>> transmitted herewith is intended only for use by the individual or
>> entity to which it is addressed. If the reader of this message is
>> not the intended recipient, you are hereby notified that any review,
>> retransmission, dissemination, distribution, copying or other use of,
>> or taking of any action in reliance upon this information is strictly
>> prohibited. If you have received this communication in error, please
>> contact the sender and delete the material from your computer.
>
>
> ------------------------------------------------------------------------
>
> The information contained in this e-mail is confidential and/or
> proprietary to Capital One and/or its affiliates. The information
> transmitted herewith is intended only for use by the individual or
> entity to which it is addressed. If the reader of this message is not
> the intended recipient, you are hereby notified that any review,
> retransmission, dissemination, distribution, copying or other use of,
> or taking of any action in reliance upon this information is strictly
> prohibited. If you have received this communication in error, please
> contact the sender and delete the material from your computer.
>