Not a pure dropwizard question this! Hope you guys answer.
Is there a way to change the existing query parameters using a jersey filter. I have clients passing in id's like this
/v1/path?id=1,2,3
What I would like is for them to show up as a list in my resource class //Resource class
public List<Something> getFilteredList(@QueryParam("id") List<String> ids) {//
Right now, the ids list contains 1 string which is 1,2,3. I would like to apply a filter and change any comma separated query parameters into multivalued parameters so that the resource method gets a list instead.
Is this at all possible? I tried a filter but the query params given by Jersey's
ContainerRequestContext.getUriInfo().getQueryParameters()
is immutable.
What's a good way to solve this problem?
--
You received this message because you are subscribed to the Google Groups "dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-us...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
public class ListLongParam extends AbstractParam<List<Long>> {
public ListLongParam(String input) {
super(input);
}
@Override
protected List<Long> parse(String input) throws Exception {
if (Strings.isNullOrEmpty(input)) {
return ImmutableList.of();
}
final Iterable<String> splitter = Splitter.on(',').omitEmptyStrings()
.trimResults().split(input);
final ImmutableList.Builder<Long> builder = ImmutableList.builder();
for (String value : splitter) {
try {
builder.add(Long.parseLong(value));
} catch (NumberFormatException ignore) {
// ignore invalid numbers
}
}
return builder.build();
}
}
-Justin