0

I am trying passing time in a query param to WildFly 20 + RestEasy.
@GET public void takeTime(@QueryParam("time") Date time) {...}

RestEasy throws this error:
Unable to extract parameter from http request: javax.ws.rs.QueryParam("time") value is '2021-01-14T12%3A17%3A29.000Z'

From "%3A" it is obvious, where the problem is. RestEasy does not unescape query parametr. But only in case of Date type.
When I change java type from Date to String and write parameter to log, colons in time are correctly written instead of %3A.

Is this correct behaviour or a bug in RestEasy ? Or it is a configurable feature ?

martins
  • 371
  • 3
  • 10
  • 1
    Does this answer your question? [CXF JAXRS - How do I pass Date as QueryParam](https://stackoverflow.com/questions/9520716/cxf-jaxrs-how-do-i-pass-date-as-queryparam) – areus Jan 14 '21 at 12:39
  • Thanks for a link and quick answer. Actually I have already seen that thread. Unfortunately it seems to be related to ISO8601 parsing, not to url escaping. But maybe it gives a solution: migrate from buggy RestEasy to outdated but working CXF. – martins Jan 14 '21 at 12:43
  • JAX-RS specifies that `@QueryParam` will try to call a constructor with a single String param, and calling `new Date("2021-01-14T12:17:29.000Z")` throws an `IllegalArgumentException`. Change `Date` to a custom class with a constructor that requires a single String, and you can check if Resteasy really unescapes the parameter or not – areus Jan 14 '21 at 12:54
  • https://javaee.github.io/javaee-spec/javadocs/javax/ws/rs/QueryParam.html (point 2) – areus Jan 14 '21 at 12:55
  • 1
    Thanks, you were right. RestEasy really unescapes argument and passes to Date constructor. Unescaped text in error message was a red herring. – martins Jan 14 '21 at 13:59
  • look at the second answer: https://stackoverflow.com/a/31476292/11751648 you need to create a `ParamConverter` and a `ParamConverterProvider`. Regarding that solution, just clarify that you can register the provider just adding a `@Provider` annotation to `DateParameterConverterProvider` – areus Jan 14 '21 at 14:09

0 Answers0