Resource @NotNull LongParam validation in 1.0 problem

288 views
Skip to first unread message

Chris Micali

unread,
Sep 9, 2016, 11:55:42 AM9/9/16
to dropwizard-user
Hey Guys,

    I'm in process trying to upgrade a DW 0.8.x application to 1.0 and I've run into something I am not sure I understand. We have a lot of endpoints that include LongParams, for example:

    @GET
   
@UnitOfWork
   
public List<User> getAll(@NotNull @QueryParam("account_id") LongParam accountId

    This no longer works, as we now get a:

HV000186: The constraint of type 'javax.validation.constraints.NotNull' defined on 'getAll.account_id' has multiple matching constraint validators which is due to an additional value handler of type 'io.dropwizard.jersey.validation.ParamValidatorUnwrapper'. It is unclear which value needs validating. Clarify configuration via @UnwrapValidatedValue.

   So, I understand this probably now needs @UnwrapValidatedValue after reading http://www.dropwizard.io/1.0.0/docs/manual/validation.html#optional-t-constraints 

   But: does this mean everywhere we want to make a long parameter required we have to add that annotation? 
   
   This is such a basic and common case, the following seems very verbose:

    @GET
   
@UnitOfWork
   
public List<User> getAll(@UnwrapValidatedValue @NotNull @QueryParam("account_id") LongParam accountId

    Am I missing something?

Thanks,
Chris

Evan Meagher

unread,
Sep 12, 2016, 11:33:04 PM9/12/16
to dropwiz...@googlegroups.com
As far as I understand it, you're correct—an @UnwrapValidatedValue annotation is required anywhere you use a LongParam (or IntParam, UUIDParam, etc) along with a validation annotation.

This is rather unfortunate. The other typical use case for the @UnwrapValidatedValue annotation is within representation classes, in which case you can simply annotate the affected field once and forget about it in your resource classes.

--
You received this message because you are subscribed to the Google Groups "dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-user+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Evan Meagher

Chris Micali

unread,
Sep 13, 2016, 10:35:06 AM9/13/16
to dropwizard-user
Thanks. Ideally Hibernate Validator would provide a way to set a default for this (say, for this unwrappable type, default unwrap validated value to true) but I could not find a way to do this now. @UnwrapValidatedValue is also marked as experimental.

For the time being we build a maven plugin that uses javaassist to auto-add @UnwrapValidatedValue to any resource method parameters that need it. It's ugly, but it works.


To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-us...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Evan Meagher
Reply all
Reply to author
Forward
0 new messages