Is it possible to customize the output of @QueryParam?

53 views
Skip to first unread message

Florian Friemel

unread,
Aug 24, 2016, 7:33:35 AM8/24/16
to RestyGWT
Our team needs to consume a rest-ish API that expects path parameters in the form of

api/v1/foo?bar[baz]

instead of 

api/v1/foo?bar=baz or api/v1/foo?bar=[baz]

Now, if we use @QueryParam("bar") String bar, the result is foo?bar=[baz] (if bar.equals("[baz]") of course), which the API does not accept.

What we can do ist write something like @QueryParam("bar[baz]") String bar which results in foo?bar[baz]=asdf. This works, but unfortunately there is also bar[qux] and bar[quux], and we would have to create a request method for every possible value that bar can take (and combinations thereof).

So instead of  getBar(@QueryParam("bar") List<String> bar ...

we need to create 
getBar(@QueryParam("bar[baz]") String bar ...
getBar(@QueryParam("bar[qux]") String bar ...
getBar(@QueryParam("bar[baz]") String bar, @QueryParam("bar[qux]") String bar ...
... // and so on

Is there any way we can influence how resty generates the query string?


http://stackoverflow.com/questions/39038949/api-expects-queries-to-look-like-foobarbaz-instead-of-foobar-baz-is-thi

Paul Mazzuca

unread,
Nov 23, 2016, 2:57:12 PM11/23/16
to RestyGWT
try something like this...

@Path("api?bar[blah]")

public void test(@PathParam("blah") String blah, MethodCallback<...> callBack);

Reply all
Reply to author
Forward
0 new messages