Jersey 1.x is replacing the plus symbol with a space symbol. How can I prevent this?
java, jersey, jersey-1.0
Solution
Apart from @IanRoberts's suggestion, you could make use of the `@Encoded` annotation to get to the original undecoded value of you parameter (by default Jersey decodes the values and that's why `id+ASC` becomes `id ASC` in your code).
The following example retrieves the decoded value as for the default behavior:
@GET
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response test(@QueryParam("sort") String sort) {
// sort is "id ASC"
return Response.ok().entity(sort).build();
}
To change the behavior you just add `@Encoded`:
@GET
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response test(@QueryParam("sort") @Encoded String sort) {
// sort is "id+ASC"
return Response.ok().entity(sort).build();
}
Problem
I'm using the jersey client to send a query param to my jersey server. This is the query: `?sort=id+ASC` But in my code that retrieves this query param, `return uriInfo.getQueryParameters().getFirst("sort");`, this value evaluates to `id ASC`. Why is this happening and how can I prevent it?