ignore optional @Query parameters

Is there a possibility to ignore some of the optional @Query parameters dynamic if the corresponding value is not declared?

public class Services {

public Response getUsers(
    @QueryParam("from") int from,
    @QueryParam("to") int to,
    @QueryParam("age") int age,
    @QueryParam("name") String name
    @QueryParam("username") String username) 

2 answers

  • answered 2018-11-07 20:16 Deadpool

    In JAX-RS parameters are not mandatory, if you don't send value to parameters the default value will be null, you can also use @DefaultValue annotation to provide default value.

    Use can also use spring frame work @RequestParam and you can specify required=false so which is optional here

  • answered 2018-11-07 20:16 joliva

    You could use @DefaultValue so if the param is not filled you get the default value