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.

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay