2

Invoking a REST with a boolean parameter receives the value false even though passing true on the client side.

Client:

$http.post("http://localhost/getServers/?light=true")

Server:

@Path("/getServers")
@POST
@Produces({MediaType.APPLICATION_JSON})
public Response getServers(
  @Context HttpServletRequest request,
  @DefaultValue("true") @QueryParam("light") boolean light)
{
  // light is false even though true was passed
  ...
}
AlikElzin-kilaka
  • 34,335
  • 35
  • 194
  • 277

1 Answers1

2

It seems that the slash (/) before the question mark (?) was the problem.

After removing the slash on the client side, everything worked fine.

This worked:

$http.post("http://localhost/getServers?light=true")

BUT, from reading on the web, a slash preceding a question mark is a legitimate syntax :(

AlikElzin-kilaka
  • 34,335
  • 35
  • 194
  • 277
  • 1
    It is legitimate in a general HTTP request but not for the contract you wrote, i.e. `@Path("/getServers")` is not the same as `@Path("/getServers/")`. – Gaël J Oct 21 '15 at 11:20