private static JSONValue encodeCollection(Collection collection, Type type,
ApplicationConnection connection) {
JSONArray jsonArray = new JSONArray();
int idx = 0;
for (Object o : collection) {
JSONValue encodedObject = encodeChildValue(o, type, 0, connection);
jsonArray.set(idx++, encodedObject);
}
if (collection instanceof Set) {
return jsonArray;
} else if (collection instanceof List) {