Reputation: 265
I have a API endpoint method like this:
@ApiMethod(name = "test")
public TestModel test(@Named("testArray") ArrayList<String> myTest) {
for (String i:myTest){
log.warning("i=="+i);
}
A request is made as such:
{
"testArray":[
"ID1",
"ID2"
]
}
However, when I check my log (and also the problems this caused in my app), I see
i=="ID1,ID2"
not how i expected to see:
i=="ID1"
i=="ID2"
as the output. It is putting both elements of the array into myTest(0). How do I populate the Array correctly?
Upvotes: 2
Views: 495
Reputation: 3591
This issue doesn't appear to occur on the latest SDK 1.9.22.
I'm wondering how you're creating the request, and if it's possible that you're just joining the strings with commas as a single element in the array that you send. While I know it sounds crazy to do this deliberately and I don't think you're doing that, it's possible that some layer of abstraction below your code does it?
Another possibility is that you're not using the generated client library for your Endpoints API (you really should, it does a lot of work that you'd end up replicating on your own), and you're forming raw JSON to send over? In that case, I can see how maybe the request that ultimately gets sent might be different from what you expect, collapsing all the values inside the array that "testArray" is a key to into a comma-separated list.
So, my best advice is to examine how you form the request, and if possible, get access to the raw request itself inside your endpoints method to see what was sent.
Upvotes: 2
Reputation: 2595
The easiest way, since this seems like a bug, is to not use a named parameter. Create a new request class that has a list field and use that as an unnamed (aka resource) parameter, instead.
Upvotes: 1