private void createProperty()

in src/main/java/org/apache/sling/servlets/get/impl/util/JsonObjectCreator.java [187:236]


    private void createProperty(final JsonObjectBuilder obj, final String key, final Object value) {
        if (value == null) {
            return;
        }
        if (value instanceof Supplier) {
            createProperty(obj, key, ((Supplier) value).get());
            return;
        }

        Object[] values = null;
        if (value.getClass().isArray()) {
            final int length = Array.getLength(value);
            // write out empty array
            if (length == 0) {
                obj.add(key, Json.createArrayBuilder());
                return;
            }
            values = new Object[Array.getLength(value)];
            for (int i = 0; i < length; i++) {
                values[i] = Array.get(value, i);
                while (values[i] instanceof Supplier) {
                    values[i] = ((Supplier) values[i]).get();
                }
            }
        }

        // 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.add(":" + key, getLength(-1, key, (InputStream) value));
            } else {
                final JsonArrayBuilder result = Json.createArrayBuilder();
                for (int i = 0; i < values.length; i++) {
                    result.add(getLength(i, key, (InputStream) values[i]));
                }
                obj.add(":" + key, result);
            }
            return;
        }

        if (values != null) {
            obj.add(key, getValue(values));
        } else {
            obj.add(key, getValue(value));
        }
    }