users@jersey.java.net

[Jersey] Re: DropWizard and Hibernate Validator

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

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