com.capitalone.dashboard.model.adapter.FeatureFlagAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
Core package shared by API layer and Microservices
package com.capitalone.dashboard.model.adapter;
import com.capitalone.dashboard.model.FeatureFlag;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import java.lang.reflect.Type;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
public class FeatureFlagAdapter implements JsonDeserializer {
@Override
public FeatureFlag deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
FeatureFlag featureFlag = new FeatureFlag();
JsonObject jsonObject = jsonElement.getAsJsonObject();
if (jsonObject == null) return null;
Map b = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
JsonObject flags = jsonObject.getAsJsonObject("flags");
Set> entries = flags.entrySet();
for (Map.Entry entry: entries) {
b.put(entry.getKey(),getBoolean(flags, entry.getKey()));
}
featureFlag.setFlags(b);
featureFlag.setName(getStringValue(jsonObject,"name"));
featureFlag.setDescription(getStringValue(jsonObject,"description"));
return featureFlag;
}
private boolean getBoolean(JsonObject jsonObject, String key) {
if (jsonObject == null || jsonObject.get(key) == null) return false;
return jsonObject.get(key).getAsBoolean();
}
private String getStringValue(JsonObject jsonObject, String key) {
if (jsonObject == null || jsonObject.get(key) == null) return null;
return jsonObject.get(key).getAsString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy