DEV Community

Cover image for How to set default value to query param in jax-rs
Adrian Matei for Codever

Posted on • Edited on • Originally published at codever.dev

1 1

How to set default value to query param in jax-rs

Use the DefaultValue annotation parameter (accepts strings) where you set the default value alongside the QueryParam annotation

@GET
@Path("/bookmarks")
@Produces(MediaType.APPLICATION_JSON)
@Operation(
    summary = "Return bookmarks from repository",
    description = "Return bookmarks from repository")
@ApiResponses({
    @ApiResponse(responseCode = "200", description = "OK"),
    @ApiResponse(responseCode = "403", description = "Forbidden")
})
@RolesAllowed(ADMIN_ROLE)
public void getAllBookmarks(
    @Parameter(description = "max number of returned bookmarks")
    @DefaultValue(Integer.MAX_VALUE + "")
    @QueryParam("maxResult") Integer maxResult) {
  bookmarksService.getBookmarks(maxResult);
}
Enter fullscreen mode Exit fullscreen mode

Shared with ❤️ from Codever. Use 👉 copy to mine functionality to add it to your personal snippets collection.

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

Billboard image

Try REST API Generation for MS SQL Server.

DevOps for Private APIs. With DreamFactory API Generation, you get:

  • Auto-generated live APIs mapped from database schema
  • Interactive Swagger API documentation
  • Scripting engine to customize your API
  • Built-in role-based access control

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay