- for (Object key : templates.keySet()) {
- String fields = (String) templates.get(key);
- String[] fieldsInArray = fields.split(",");
- Template template = new Template((String) key, new ArrayList<>(Arrays.asList(fieldsInArray)));
+ LinkedHashMap<String, Template> generatedTemplates = new LinkedHashMap<>();
+ JsonObject templates = JsonUtils.GSON.fromJson(jsonTemplates, JsonObject.class);
+
+ for (Map.Entry<String, JsonElement> templateAsJson : templates.entrySet()) {
+ Template template = new Template(templateAsJson.getKey());
+ JsonObject templateBody = (JsonObject) templateAsJson.getValue();
+ for (Map.Entry<String, JsonElement> field : templateBody.entrySet()) {
+ String fieldName = field.getKey();
+ JsonObject bodyFieldAsJson = (JsonObject) field.getValue();
+ Object fieldValue = bodyFieldAsJson.get("defaultValue").getAsString();
+ Boolean fieldVisible = bodyFieldAsJson.get("visible").getAsBoolean();
+ Boolean fieldStatic = bodyFieldAsJson.get("static").getAsBoolean();
+ Field bodyField = new Field(fieldName, fieldValue, fieldVisible, fieldStatic);
+ template.getFields().add(bodyField);
+ }