Validation not working -- what am I missing?

430 views
Skip to first unread message

Ty Sarna

unread,
Aug 12, 2015, 11:14:16 AM8/12/15
to dropwizard-user
Environment: Dropwizard 0.8.1, Java 1.8

I can't get Dropwizard's validation support to do anything. I believe I'm following what the manual suggests. Using the following resource, for example (and many variants using @Valid on the model class attributes, @Validated instead of @Valid, hibernate's @NotEmpty instead of javax.validation.constraints.NotNull, etc):

@Path("/test")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class TestResource {
   
static public class ModelClass {
       
@JsonProperty("only_null") @Null public String onlyNull;
       
@JsonProperty("not_null") @NotNull public String notNull;
   
}

   
@PUT
   
public ModelClass testContainer(@Valid ModelClass record) {
       
return record;
   
}
}

If I PUT the following:

{"only_null":"shouldFail"}

rather than the expected 422, I get back:

{"only_null":"shouldFail","not_null":null}

What am I missing here? Is there some configuration that needs to be turned on to enable the validation?

Ted M. Young [@jitterted]

unread,
Aug 12, 2015, 1:38:07 PM8/12/15
to dropwiz...@googlegroups.com
This works for me (I get a 422), so perhaps there's something missing? If you have a pointer to a Github project that has the POM files, Application class, etc., that would help.

;ted "theodore" young

--
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-us...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages