de.zalando.toga.generator.dimensions.Dimension Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of toga Show documentation
Show all versions of toga Show documentation
A selection of tools to manipulate JSON and JSON-Shema
package de.zalando.toga.generator.dimensions;
import com.fasterxml.jackson.databind.JsonNode;
import java.util.List;
public abstract class Dimension {
protected final String name;
public Dimension(String name) {
this.name = name;
}
public static Dimension from(String name, JsonNode node) {
JsonNode typeNode = node.path("type");
if (typeNode.isMissingNode() || !typeNode.isValueNode()) {
throw new IllegalArgumentException("Could not derive type from node [" + node.toString() + "].");
}
String type = typeNode.asText();
switch (type) {
case "object":
return new ObjectDimension(name, node);
case "string":
return new StringDimension(name, node);
default:
throw new IllegalArgumentException("JSON attribute with type [" + type + "] is not supported.");
}
}
public String getFieldName() {
return name;
}
/**
* Generate a list of JSON representations of the dimension.
* This generated JSON is intended to be combined into JSON objects right away without further modification.
*
* @return a list of json representations with all the different options the dimension contains.
*/
public abstract List getValueDimensions();
}