Cloud Endpoints Collection Parameter

血红的双手。 提交于 2019-12-03 21:04:00

问题


Im using Google App Engine Cloud Endpoints and Im trying to receive a collection parameter . Not sure if I can do this. I know I can return a List or any Collection.

This:

   public List<Pair> initializationSetup(Pair pPair){}

Works fine, but If I try to receive a list of pairs, the .api file is not created.

   public List<Pair> initializationSetup(List<Pair> pPairs){

Thanks


回答1:


Cloud Endpoints only deals with classes having the bean standard.

So, I created a new class named ObjectListContainer:

public class ObjectListContainer {
    public List<Object> getObjectsList() {
        return ObjectsList;
    }
    public void setObjectsList(List<Object> objectsList) {
        ObjectsList = objectsList;
    }
    private List<Object> ObjectsList;
}

Same problem if you are trying to return a String, you can't. You have to make a StringContainer.




回答2:


I have used a similar solution after think during long hours . Try this:

public class JsonList<T> { 
private List<T> listItens;

public List<T> getListItens() {
    return listItens;
}

public void setListItens(List<T> listItens) {
    this.listItens = listItens;
}}

and in your method:

@ApiMethod(
        name = "name",
        path = "path",
        httpMethod = ApiMethod.HttpMethod.POST)
public CollectionResponse<Information> getInformation(JsonList<String> listOfItens) {}


来源:https://stackoverflow.com/questions/14763061/cloud-endpoints-collection-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!