@DefaultValue is not compatible with @PathParameter in RESTful framework

I got a requirement that I need a default value for @PathParameter

.

And this is what my code looks like:

    @GET
    @Path("/family/{member}")
    public Response responseMsg( @DefaultValue("Father") @PathParam("member")  String pathParameter) {}

      

The compiler will not show any errors, and the application will of course not act as I expected.

because uri "/ family / null

" will not match the path " /family/{member}

" but " /family/

"

May I know if there is a way to assign a default value to @PathParam

and how? and also i want to know if compatible @DefaultValue

with @QueryParameter

?

+3


source to share


1 answer


I think the best practice here would be to redirect the method annotated with @Path("/family/")

to the method you provided with the default you want:



@GET
@Path("/family")
public Response redirectingMethod() {
    return responseMsg("Father");
}

      

0


source







All Articles