I am using Google Cloud Endpoints for a simple Android application. However, I am not able to pass a list of strings as parameter to an API method. If I use List as parameter type, build is fine, but strings in the list I pass are concatenated, separated by comma, and there is only one entry in the list the server receives, this concatenated string. For example if in the client I pass ["a", "b", "c"] the server receives ["a,b,c"]. Could you help me with a correct way to do it?
Edit1:
In Cloud Endpoint I have:
@ApiMethod(name = "addGroup")
public void addGroup(@Named("members") List<String> members,
@Named("session") String sessionString) throws ForbiddenException
In the Android client:
final List<String> selectedFriends = new ArrayList<>();
selectedFriends.add("A");
selectedFriends.add("B");
selectedFriends.add("C");
ServerApi.getInstance().addGroup(selectedFriends,Session.JSONSession()).execute();
Edit2: The class generated automatically looks decompiled as:
public class AddGroup extends MyApiRequest<Void> {
private static final String REST_PATH = "addGroup/{members}/{session}";
@Key
private List<String> members;
@Key
private String session;
protected AddGroup(List<String> this$0, String members) {
super(MyApi.this, "POST", "addGroup/{members}/{session}", (Object)null, Void.class);
this.members = (List)Preconditions.checkNotNull(members, "Required parameter members must be specified.");
this.session = (String)Preconditions.checkNotNull(session, "Required parameter session must be specified.");
}
... everything as expected
}
What confuses me is the this$0 parameter and the second parameter called members (the session parameter looks to be skipped?).
Thank you!
I'm not sure why the annotation processor is somehow injecting
this$0
as a path parameter. Does your API really need to have themembers
andsession
in part of the path? Or, can/should these both be query parameters instead (see the auto-generated code and how it has injected them there)? Try removing the@Named
annotation for both of these, which should make them query parameters automatically.