public static ApiRegions parse()

in src/main/java/org/apache/sling/feature/extension/apiregions/api/ApiRegions.java [250:289]


    public static ApiRegions parse(final JsonArray json) throws IOException {
        try {
            final ApiRegions regions = new ApiRegions();

            for (final JsonValue value : json) {
                if (value.getValueType() != ValueType.OBJECT) {
                    throw new IOException("Illegal api regions json " + json);
                }
                final JsonObject obj = (JsonObject) value;

                final ApiRegion region = new ApiRegion(obj.getString(NAME_KEY));

                for (final Map.Entry<String, JsonValue> entry : obj.entrySet()) {
                    if (NAME_KEY.equals(entry.getKey())) {
                        continue; // already set
                    } else if (entry.getKey().equals(EXPORTS_KEY)) {
                        for (final JsonValue e : (JsonArray) entry.getValue()) {
                            ApiExport.fromJson(region, e);
                        }
                    } else if (entry.getKey().equals(Artifact.KEY_FEATURE_ORIGINS)) {
                        final Set<ArtifactId> origins = new LinkedHashSet<>();
                        for (final JsonValue origin : (JsonArray) entry.getValue()) {
                            origins.add(ArtifactId.fromMvnId(((JsonString) origin).getString()));
                        }
                        region.setFeatureOrigins(origins.toArray(new ArtifactId[0]));

                        // everything else is stored as a string property
                    } else {
                        region.getProperties().put(entry.getKey(), ((JsonString) entry.getValue()).getString());
                    }
                }
                if (!regions.add(region)) {
                    throw new IOException("Region " + region.getName() + " is defined twice");
                }
            }
            return regions;
        } catch (final JsonException | IllegalArgumentException e) {
            throw new IOException(e);
        }
    }