private void parse()

in src/main/java/org/apache/sling/contentparser/json/internal/JSONContentParser.java [111:165]


    private void parse(ContentHandler handler, JsonObject object, ParserOptions parserOptions, String path) throws IOException {
        // parse JSON object
        Map<String, Object> properties = new HashMap<>();
        Map<String, JsonObject> children = new LinkedHashMap<>();
        for (Map.Entry<String, JsonValue> entry : object.entrySet()) {
            String childName = entry.getKey();
            Object value = null;
            boolean ignore = false;
            try {
                value = convertValue(parserOptions, entry.getValue());
            } catch (IllegalArgumentException ex) {
                if (parserOptions.getIgnoreResourceNames().contains(childName) || parserOptions.getIgnorePropertyNames()
                        .contains(removePrefixFromPropertyName(parserOptions.getRemovePropertyNamePrefixes(), childName))) {
                    ignore = true;
                } else {
                    throw new IOException(ex);
                }
            }
            boolean isResource = (value instanceof JsonObject);
            if (!ignore) {
                if (isResource) {
                    ignore = parserOptions.getIgnoreResourceNames().contains(childName);
                } else {
                    for (String prefix : parserOptions.getRemovePropertyNamePrefixes()) {
                        if (childName.startsWith(prefix)) {
                            childName = childName.substring(prefix.length());
                            break;
                        }

                    }
                    ignore = parserOptions.getIgnorePropertyNames().contains(childName);
                }
            }
            if (!ignore) {
                if (isResource) {
                    children.put(childName, (JsonObject) value);
                } else {
                    properties.put(childName, value);
                }
            }
        }
        String defaultPrimaryType = parserOptions.getDefaultPrimaryType();
        if (defaultPrimaryType != null && !properties.containsKey("jcr:primaryType")) {
            properties.put("jcr:primaryType", defaultPrimaryType);
        }

        // report current JSON object
        handler.resource(path, properties);

        // parse and report children
        for (Map.Entry<String, JsonObject> entry : children.entrySet()) {
            String childPath = path.endsWith("/") ? path + entry.getKey() : path + "/" + entry.getKey();
            parse(handler, entry.getValue(), parserOptions, childPath);
        }
    }