users@jersey.java.net

[Jersey] Re: DropWizard and Hibernate Validator

From: cowwoc <cowwoc_at_bbs.darktech.org>
Date: Thu, 01 Nov 2012 23:22:46 -0400

On 01/11/2012 9:34 PM, cowwoc wrote:
> On 01/11/2012 8:38 PM, Tatu Saloranta wrote:
>> On Thu, Nov 1, 2012 at 1:44 PM, cowwoc <cowwoc_at_bbs.darktech.org> wrote:
>>> Hi Tatu,
>>>
>>> I tried playing with DropWizard but now I'm getting frustrated
>>> with the
>>> component that I knew would annoy me: Hibernate Validator (I've had bad
>>> experiences with anything related to Hibernate).
>>>
>>> I created the sample application mentioned here:
>>> http://dropwizard.codahale.com/getting-started/
>>>
>>> But then I added the following method inside HelloWorldResource:
>>>
>>> private void foo(@NotNull @Valid String value) {
>>> System.out.println("*******************inside: " + value);
>>> }
>>>
>>> and I invoke foo(null) from sayHello(). I am expecting the
>>> validator to
>>> throw an exception since I am passing in null, but instead the calls
>>> continues as if nothing is wrong. What am I missing?
>> If you are calling it directly, there's nothing intercepting it. These
>> are validated by code that would call resource method?
>>
>> -+ Tatu +-
>
> Hi Tatu,
>
> Clearly I misunderstood how this works. Is there a "Getting
> started" trail for Hibernate Validator? I skimmed through their
> website but didn't find anything. I was looking for something that
> would let me annotate parameters with @NotNull and throw
> NullPointerException (with a meaningful message) if the parameter was
> null. Is HV right for the job or should I be looking somewhere else?
> Right now I am hand-coding the checks at the beginning of each method
> body.
>
> Gili

http://musingsofaprogrammingaddict.blogspot.ca/2011/01/method-validation-with-hibernate.html
and
https://github.com/gunnarmorling/methodvalidation-integration/tree/master/methodvalidation-cdi/src/main/java/de/gmorling/methodvalidation/cdi
seem to cover my question... Looking at
com.yammer.dropwizard.validation.Validator, it seems that DropWizard
doesn't support method validation. I filed this issue:
https://github.com/codahale/dropwizard/issues/203

Gili