io.nosqlbench.nb.api.config.params.JsonBackedConfigElement Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of driver-cql-shaded Show documentation
Show all versions of driver-cql-shaded Show documentation
A Shaded CQL ActivityType driver for http://nosqlbench.io/
package io.nosqlbench.nb.api.config.params;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.util.Set;
public class JsonBackedConfigElement implements ElementData {
private final Gson gson = new GsonBuilder().setPrettyPrinting().create();
private final JsonObject jsonObject;
public JsonBackedConfigElement(JsonObject jsonObject) {
this.jsonObject = jsonObject;
}
@Override
public Object get(String name) {
return jsonObject.get(name);
}
@Override
public Set getKeys() {
return jsonObject.keySet();
}
@Override
public boolean containsKey(String name) {
return jsonObject.keySet().contains(name);
}
@Override
public T convert(Object input, Class type) {
if (input instanceof JsonElement) {
T result = gson.fromJson((JsonElement) input, type);
return result;
} else {
throw new RuntimeException("Unable to convert json element from '" + input.getClass().getSimpleName() + "' to '" + type.getSimpleName() + "'");
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy