0

在我的GCP端點v2項目中,我創建了一個返回POJOS集合的服務。 我注意到,當返回一個List或一個CollectionResponse @ApiMethod(name =)不起作用。GCP端點v2:@ApiMethod(name =)返回集合時不起作用

下面的例子:

@ApiMethod(name = "getCountryList", 
    httpMethod = ApiMethod.HttpMethod.GET) 
public CollectionResponse<Country> getCountryList() { 

List<Country> countryList = null; 
Connection con = null; 

try{ 
    con = DbUtils.getConnection(); 
    countryList = CountryApi.getAll(con); 

    return CollectionResponse.<Country> builder().setItems(countryList).build(); 
     //...... 

我除了有暴露名爲getCountryList我的方法,而它被這個名爲「collectionresponse_country」暴露
也在這裏是openapi.json文件,該文件是一致的

enter image description here

回答

0

我已經找到了答案,這是從我犯的一個錯誤(和文檔不再詳細閱讀:-() 我必須使用@ApiMethod路徑屬性,如下所示:

@ApiMethod(name = "getCountryList", 
      httpMethod = ApiMethod.HttpMethod.GET, 
      path = "getCountryList") 
    public CollectionResponse<Country> getCountryList()