class ImmutableFeatures implements Features {

    @Override
    public JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate) {
        final Predicate<JsonField> predicate = schemaVersion.and(thePredicate);
        final JsonObjectBuilder jsonObjectBuilder = JsonFactory.newObjectBuilder();

        jsonObjectBuilder.set(JSON_SCHEMA_VERSION, schemaVersion.toInt(), predicate);

        features.values()
                .forEach(feature -> {
                    final JsonKey key = JsonFactory.newKey(feature.getId());
                    final JsonValue value = feature.toJson(schemaVersion, thePredicate);
                    final JsonFieldDefinition<JsonObject> fieldDefinition =
                            JsonFactory.newJsonObjectFieldDefinition(key, FieldType.REGULAR, JsonSchemaVersion.V_1,
                                    JsonSchemaVersion.V_2);
                    final JsonField field = JsonFactory.newField(key, value, fieldDefinition);
                    jsonObjectBuilder.set(field, predicate);
                });

        return jsonObjectBuilder.build();
    }

    private  ImmutableFeatures(final Map<String, Feature> features);

}