簡體   English   中英

將盒裝基元列表傳遞給Google Cloud Endpoint

[英]Passing list of boxed primitives to Google Cloud Endpoint

我正在努力將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庫時,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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM