Object[] values = null;
if (value.getClass().isArray()) {
final int length = Array.getLength(value);
// write out empty array
if ( length == 0 ) {
obj.put(key, new JSONArray());
return;
}
values = new Object[Array.getLength(value)];
for(int i=0; i<length; i++) {
values[i] = Array.get(value, i);
}
}
// special handling for binaries: we dump the length and not the data!
if (value instanceof InputStream
|| (values != null && values[0] instanceof InputStream)) {
// TODO for now we mark binary properties with an initial colon in
// their name
// (colon is not allowed as a JCR property name)
// in the name, and the value should be the size of the binary data
if (values == null) {
obj.put(":" + key, getLength(valueMap, -1, key, (InputStream)value));
} else {
final JSONArray result = new JSONArray();
for (int i = 0; i < values.length; i++) {
result.put(getLength(valueMap, i, key, (InputStream)values[i]));
}
obj.put(":" + key, result);
}
return;
}
if (!value.getClass().isArray()) {
obj.put(key, getValue(value));
} else {
final JSONArray result = new JSONArray();
for (Object v : values) {
result.put(getValue(v));
}
obj.put(key, result);
}
}