JAX-RS:双@PathParam传递

时间:2015-09-16 10:50:03

标签: rest jax-rs path-parameter

我想通过双路障碍,如5,5.0,0.5,3.5,3.65等。

所以我在JAX-RS资源上制作了这样的方法:

 @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 
 }

但即使没有Regex模式,这种方法似乎也无法正常工作。

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)

更新

抱歉没有正则表达式它正常工作正则表达式存在一些问题   \ d +(\。\ d +)?我一直在尝试使用: [0-9] +(\。[0-9] +)?,只是 \ S + (不是空格)

1 个答案:

答案 0 :(得分:0)

尝试使用BigDecimal代替Double,例如

@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