将盒装基元列表传递给Google Cloud Endpoint

时间:2014-08-18 08:27:57

标签: java android google-app-engine google-cloud-endpoints

我正在努力将Lists作为Google Cloud Endpoints的方法参数。

文件说明

  

支持的参数类型如下:

     
      
  • java.util.Collection参数类型
  •   

我试着这样做,但它只是不起作用。 基本端点方法:

@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");
        }
    }
}

当我使用API​​ Exploler执行此方法时,生成的URL为:

POST http://localhost:8080/_ah/api/billEndpoint/v1/testMethod?longList=5&longList=6

方法正确执行。

但是当使用Android库时,网址将更改为:

http://APP_ENGINE_BACKEND:8080/_ah/api/billEndpoint/v1/testMethod/5,6

,端点返回404代码。

可以将List作为方法参数,如果我做错了吗?

2 个答案:

答案 0 :(得分:2)

请将@Nullable注释添加到您的方法中,这会将您的集合类型参数从路径转换为查询参数。

https://developers.google.com/appengine/docs/java/endpoints/annotations#nullable

答案 1 :(得分:1)

更直接的方法是向API_METHOD注释添加路径属性,而不在路径中包含List参数。如上所述here:“如果指定了路径,则可以通过不在路径中包含参数来创建参数查询参数”

在你的情况下它应该是:

@ApiMethod(name =“testMethod”,path =“testMethod”httpMethod = HttpMethod.POST)

相关问题