users@jersey.java.net

[Jersey] Re: DropWizard and Hibernate Validator

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Thu, 1 Nov 2012 20:09:30 -0700

On Thu, Nov 1, 2012 at 6:34 PM, cowwoc <cowwoc_at_bbs.darktech.org> 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.

I don't use non-POJO parameters usually; but as far as I know
everything that uses databinding does get validated, as long as
annotations are included. Validation works for configuration POJOs as
well as input POJOs.

But you will probably find more information on (Hibernate) bean
validation mailing list, drop wizard user list, or StackOverflow.
And you'd need to include declarations of things you are using I assume.

-+ Tatu +-