All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.getunleash.repository.JsonToggleParser Maven / Gradle / Ivy

There is a newer version: 9.2.4
Show newest version
package io.getunleash.repository;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.Reader;

@Deprecated()
final class JsonToggleParser {

    private JsonToggleParser() {}

    public static String toJsonString(ToggleCollection toggleCollection) {
        Gson gson = new GsonBuilder().create();
        return gson.toJson(toggleCollection);
    }

    public static ToggleCollection fromJson(Reader reader) throws IllegalStateException {
        Gson gson =
                new GsonBuilder()
                        .registerTypeAdapter(
                                ToggleCollection.class, new JsonToggleCollectionDeserializer())
                        .create();
        ToggleCollection gsonCollection = gson.fromJson(reader, ToggleCollection.class);
        if (gsonCollection == null) {
            throw new IllegalStateException("Could not extract toggles from json");
        }
        return new ToggleCollection(gsonCollection.getFeatures());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy