in src/main/java/org/apache/sling/resource/inventory/impl/JsonObjectCreator.java [155:227]
private static void createProperty(final JsonObjectBuilder obj,
final ValueMap valueMap,
final String key,
final Object value) {
Object[] values = null;
if (value.getClass().isArray()) {
if (value instanceof long[]) {
values = ArrayUtils.toObject((long[])value);
} else if (value instanceof int[]) {
values = ArrayUtils.toObject((int[])value);
} else if (value instanceof double[]) {
values = ArrayUtils.toObject((double[])value);
} else if (value instanceof byte[]) {
values = ArrayUtils.toObject((byte[])value);
} else if (value instanceof float[]) {
values = ArrayUtils.toObject((float[])value);
} else if (value instanceof short[]) {
values = ArrayUtils.toObject((short[])value);
} else if (value instanceof long[]) {
values = ArrayUtils.toObject((long[])value);
} else if (value instanceof boolean[]) {
values = ArrayUtils.toObject((boolean[])value);
} else if (value instanceof char[]) {
values = ArrayUtils.toObject((char[])value);
} else {
values = (Object[]) value;
}
// write out empty array
if ( values.length == 0 ) {
obj.add(key, Json.createArrayBuilder());
return;
}
}
// 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
try {
if (values == null) {
obj.add(":" + key, getLength(valueMap, -1, key, (InputStream)value));
} else {
final JsonArrayBuilder result = Json.createArrayBuilder();
for (int i = 0; i < values.length; i++) {
result.add(getLength(valueMap, i, key, (InputStream)values[i]));
}
obj.add(":" + key, result);
}
} catch ( final JsonException ignore ) {
// we ignore this
LoggerFactory.getLogger(JsonObjectCreator.class).warn("Unable to create JSON value", ignore);
}
return;
}
try {
if (!value.getClass().isArray()) {
obj.add(key, getValue(value));
} else {
final JsonArrayBuilder result = Json.createArrayBuilder();
for (Object v : values) {
result.add(getValue(v));
}
obj.add(key, result);
}
} catch ( final JsonException ignore ) {
// we ignore this
LoggerFactory.getLogger(JsonObjectCreator.class).warn("Unable to create JSON value", ignore);
}
}