I am struggling with Lists as method parameters at Google Cloud Endpoints.
The documentations says that
The supported parameter types are the following:
- java.util.Collection of a parameter type
I tried to do it this way, but it just do not work. Basic endpoint method:
@ApiMethod(name = "testMethod", httpMethod = HttpMethod.POST)
public void testMethod(@Named("longList") List<Long> longList) {
for (Long aLong : longList) {
if (aLong < 5) {
throw new IllegalArgumentException("You can't do it");
}
}
}
When I execute this method using API Exploler the generated URL is:
POST http://localhost:8080/_ah/api/billEndpoint/v1/testMethod?longList=5&longList=6
And the method is executed correctly.
But when Android library is used the url is changed to:
http://APP_ENGINE_BACKEND:8080/_ah/api/billEndpoint/v1/testMethod/5,6
and the endpoint return 404 code.
It is possible to have List as method parameter and if it is what I am doing wrong?
A more direct way is to add a path property to the API_METHOD annotation and not include the List parameter in the path. As stated here: "If path is specified, parameters can be made query parameters by not including them in the path"
In your case it should look like:
@ApiMethod(name = "testMethod", path="testMethod" httpMethod = HttpMethod.POST)
Please add @Nullable annotation to your method, that will turn your collection-type parameter from a path into a query parameter.
https://developers.google.com/appengine/docs/java/endpoints/annotations#nullable