0

I would like to pass Double path params like 5, 5.0, 0.5, 3.5, 3.65 etc.

So I make such method on JAX-RS resource:

 @GET
 @Path("/rated-above/{minAvgRating : \\d+(\\.\\d+)? }")
 @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
 public Response getProvidersOnAverageRatedAbove( @PathParam("minAvgRating") Double minAvgRating,
                                                         @BeanParam PaginationBeanParam params) throws ForbiddenException {
             // method 
 }

But this method seems to doesn't work correctly even without Regex pattern.

Caused by: org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure: Could not find MessageBodyWriter for response object of type: pl.salonea.jaxrs.utils.ErrorResponseWrapper of media type: application/octet-stream
at org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse(ServerResponseWriter.java:67)
at org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:153)

UPDATE

Sorry without regex it works correctly there is some problem with regex \d+(\.\d+)? I have been also trying to use: [0-9]+(\.[0-9]+)? and just \S+ (not white space)

Michał Ziobro
  • 10,759
  • 11
  • 88
  • 143

1 Answers1

0

Try to use a BigDecimal instead of a Double, e.g.

@GET
@Path("/rated-above/{minAvgRating}")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public Response getProvidersOnAverageRatedAbove(@PathParam("minAvgRating") BigDecimal minAvgRating, @BeanParam PaginationBeanParam params) throws ForbiddenException {
  Double myDouble = Double.valueOf(minAvgRating.toString());
  // .. and then use myDouble
francesco foresti
  • 2,004
  • 20
  • 24
  • It's odd but I thinks there is some problem with IntelliJ compilation deployment as this hasn't been working about 20 min and then whan I have rewritten it without pattern and than again with the above pattern it starts to work – Michał Ziobro Sep 16 '15 at 11:11