Muhammet Emre
Muhammet Emre

Reputation: 349

Resource query parameter validation on jersey-dropwizard

I have a dropwizard application and in one resource i would like to have a required query parameter. I know jersey supports bean validation so i tried to use @NotNull annotation but it didn't work. Here's the code to resource:

@Path("/resource/{id}")
@Produces(MediaType.APPLICATION_JSON)
public class MyResource {
    //....constructor...

    @GET
    public String test(
        @PathParam("id") long id,
        @NotNull @QueryParam("required_param") long param) {
        //....
    }
}

In case it isn't clear, what i want to happen is whenever the client sends a request without the parameter required_param i want to return an error.

After reading the docs i thought maybe dropwizard's configuration would be the reason. So i added this piece of code into my application's run method:

environment.jersey().property("jersey.config.disableAutoDiscovery", false);
environment.jersey().property("jersey.config.server.disableAutoDiscovery", false);
environment.jersey().property("jersey.config.beanValidation.disable.server", false);

Unfortunately this didn't work either. Anyone has an idea on how to do this?

Upvotes: 0

Views: 1123

Answers (1)

ChristofferPass
ChristofferPass

Reputation: 346

Have you tried using the Long object instead of the primitive type?

Upvotes: 2

Related Questions