Cloud Endpoints Collection Parameter

2019-02-14 04:21发布

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

2条回答
仙女界的扛把子
2楼-- · 2019-02-14 05:03

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.

查看更多
手持菜刀,她持情操
3楼-- · 2019-02-14 05:03

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) {}
查看更多
登录 后发表回答