传递盒装原语列表,谷歌云端点 [英] Passing list of boxed primitives to Google Cloud Endpoint

查看:135
本文介绍了传递盒装原语列表,谷歌云端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我跟列为在谷歌云端点方法参数挣扎。

I am struggling with Lists as method parameters at Google Cloud Endpoints.

本细则说,

支持的参数类型有以下几种:

The supported parameter types are the following:


      
  • 参数类型的java.util.Collection

  •   

我试图做这种方式,但它只是不工作。
基本终点方式:

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

当我执行使用API​​ Exploler这种方法生成的网址是:

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

和正确执行了该方法。

但是,当使用的Andr​​oid库中的URL更改为:

But when Android library is used the url is changed to:

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

和端点返回404 code。

and the endpoint return 404 code.

有可能有列表作为方法的参数,如果是我做错了吗?

It is possible to have List as method parameter and if it is what I am doing wrong?

推荐答案

请@Nullable注释添加到您的方法,这将开启您的收藏类型参数从路径到一个查询参数。

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

这篇关于传递盒装原语列表,谷歌云端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆