@Valid allows null values?

1,956 views
Skip to first unread message

Ali Akhtar

unread,
Dec 27, 2016, 6:48:30 PM12/27/16
to dropwizard-user
If I have a parameter annotated with @Valid, and I send a request without a body, that allows the request through and gives me an NPE. Whaaaaat.

Is there a workaround annotation which combines @Valid and @NotNull and doesnt require me having to declare both? 

victo...@gmail.com

unread,
Dec 28, 2016, 5:34:33 AM12/28/16
to dropwizard-user
You could only use @NonNull... because @Valid only means that if it is a complex object, then its element should be checked too when they are annotated, so maybe you only need it not to be null?

Vyacheslav Rusakov

unread,
Dec 28, 2016, 5:43:09 AM12/28/16
to dropwizard-user
You can create new annotation combinening any other checks (in your case notnull and valid): https://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/#section-constraint-composition

среда, 28 декабря 2016 г., 6:48:30 UTC+7 пользователь Ali Akhtar написал:
Reply all
Reply to author
Forward
0 new messages