0

To be more specific, right now I'm having a problem with the separator on decimal numbers (comma vs dot): If the wrong separator comes in a url parameter the webservice returns 404. But I'd like to find a proper solution that will handle the JSON reading/writing as well.

Note: I've tried the answer in this other question but it references classes I don't have in my Jersey jars (If, QuantityXmlAdapter and NumberPersonalizedXmlAdapter) and I can't find a clue about them on Google.

Community
  • 1
  • 1
Victor Basso
  • 5,556
  • 5
  • 42
  • 60
  • Did you mean that the value is in the query stream (a `GET` request, in other words, a `@QueryParam`). – Paul Vargas Oct 18 '13 at 15:26
  • Yes, this first problem I had was on a "@QueryParam" but I should probably solve this also for "@PathParam" and JSON. – Victor Basso Oct 18 '13 at 16:21
  • Which version of JAX-RS and/or the version and application server that you are using? – Paul Vargas Oct 18 '13 at 18:38
  • As @Brian Roach pointed in my [other question](http://stackoverflow.com/questions/19451670/how-to-set-locale-on-gson-for-decimal-number-separators?noredirect=1#comment28861334_19451670), I'm confusing textual representation of a decimal and float/double literals. Locale doesn't affect the later. I'm fixing the client side so it doesn't send parameters in a Locale specific format. – Victor Basso Oct 21 '13 at 10:07

1 Answers1

1

I read your questions as this.

Your method

@GET
@Path('/resource/{decimal}')
public Response getResoureWithDecimal(@PathParam("decimal") double decimal)

Your request

GET /resource/1,2

Clearly, 1,2 is not a Java double and JAX-RS has no way to convert it to one.

Possible solution

Use a String as the parameter type and convert it with your own converter.

@GET
@Path('/resource/{decimal}')
public Response getResoureWithDecimal(@PathParam("decimal") String decimal) {
  double decimalAsDouble = convertStringWithCommaToDouble(decimal);
  // ...
}

The implementation of convertStringWithCommaToDouble(String) is up to you.