In the code in your original unedited question, no elements are ever added to the java.util.ArrayList object.
java.util.List<String> list = new java.util.ArrayList<String>();
Object[] array = list.toArray(); // array.length = 0
IDataCursor cursor = pipeline.getCursor();
IDataUtil.put(cursor, "array", array);
IDataUtil.put(cursor, "array.length", array.length);
cursor.destroy();
Your screenshot of the Service Result tab in Designer actually shows that ListOfFileNames
was returned by your service correctly, so that part of your code is working. I know this because if it wasn't returned, then it wouldn't be listed in the Service Result tab at all. The fact that it is listed there means that it was returned correctly.
But the reason why you think it's not working is because ListOfFileNames
is a zero-length array, and thus Designer has no value to display in the right column of the Service Result tab. If you had added at least one element to the ArrayList
before calling .toArray()
on it, then Designer will have something to show you: the resulting array's contents.
The other problem I noticed in the Designer screenshot is that ListOfFileNames
is an Object[]
, rather than a String[]
. That's because you're using .toArray()
with no arguments, which returns an Object[]
. Use the other version, .toArray(T[] a)
, as follows to make sure you get a String[]
returned:
java.util.List<String> list = new java.util.ArrayList<String>();
list.add("item1");
String[] array = list.toArray(new String[0]); // array.length = 1
IDataCursor cursor = pipeline.getCursor();
IDataUtil.put(cursor, "array", array);
IDataUtil.put(cursor, "array.length", array.length);
cursor.destroy();