将装箱原语列表传递给Google Cloud Endpoint
我正在努力将Lists作为Google Cloud Endpoints的方法参数。
文件说明了这一点
支持的参数类型如下:
- java.util.Collection参数类型
我试着这样做,但它只是不起作用。 基本端点方法:
@ApiMethod(name = "testMethod", httpMethod = HttpMethod.POST) public void testMethod(@Named("longList") List 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库时,url会更改为:
http://APP_ENGINE_BACKEND:8080/_ah/api/billEndpoint/v1/testMethod/5,6
并且端点返回404代码。
可以将List作为方法参数,如果它是我做错了吗?
请将@Nullable注释添加到您的方法中,这会将您的集合类型参数从路径转换为查询参数。
https://developers.google.com/appengine/docs/java/endpoints/annotations#nullable
更直接的方法是向API_METHOD注释添加路径属性,而不在路径中包含List参数。 如下所述:“如果指定了路径,则可以通过不在路径中包含参数来创建参数查询参数”
在你的情况下,它应该看起来像:
@ApiMethod(name =“testMethod”,path =“testMethod”httpMethod = HttpMethod.POST)
- 在android中将word文档转换为pdf
- java.lang.NumberFormatException:对于输入字符串:“null”
- java.lang.Long无法强制转换为java.lang.Double
- Android上的WiFi Direct工作不正常
- 尝试使用fileProvider从assets文件夹打开PDF文件,但它给出FileNotFoundException:没有这样的文件或目录
- Canvas OnDraw方法
- Android:如何通过with-in获取网格视图项Tag的位置另一个网格视图的set-on-item-click监听器function?
- jni调用java方法,该方法将自定义java接口作为参数
- Android:文字淡入淡出