/** * Method to recursively convert a Json tree, consisting of {@link JsonElement}s, to a to a * configuration tree, consisting of {@link ConfigurationElement}s * * @param parentConfiguration {@link ConfigurationElement} The parent configuration of the new * configurations added in this method call * @param parentJsonElement {@link JsonElement} The parent of the {@link JsonElement}s which will * be converted to {@link ConfigurationElement}s */ private void recConvertJsonTreeToConfigurationTree( ConfigurationElement parentConfiguration, JsonElement parentJsonElement) { if (parentJsonElement.isJsonObject()) { Set<Map.Entry<String, JsonElement>> childConfigurations = ((JsonObject) parentJsonElement).entrySet(); for (Map.Entry<String, JsonElement> childConfiguration : childConfigurations) { if (childConfiguration.getValue().isJsonObject()) { ConfigurationElement newConfigurationSection = new ConfigurationElement(childConfiguration.getKey()); parentConfiguration.addChildConfiguration(newConfigurationSection); recConvertJsonTreeToConfigurationTree( newConfigurationSection, childConfiguration.getValue()); } else { parentConfiguration.addChildConfiguration( new ConfigurationElement( childConfiguration.getKey(), new JsonConfigurationValue(childConfiguration.getValue()))); } } } }
/** * Method to recursively convert a configuration tree, consisting of {@link * ConfigurationElement}s, to a to a Json tree, consisting of {@link JsonElement}s * * @param parentJsonObject {@link JsonObject} The parent of the new {@link JsonElement}s added in * this method call * @param parentConfigurationElement {@link ConfigurationElement} The parent of the * configurations, which will be converted to {@link JsonElement}s */ private void recConvertConfigurationTreeToJsonTree( JsonObject parentJsonObject, ConfigurationElement parentConfigurationElement) { for (ConfigurationElement configurationElement : parentConfigurationElement.getChildren()) { if (configurationElement.isConfigurationSection()) { JsonElement newJsonElement = new JsonObject(); parentJsonObject.add(configurationElement.getName(), newJsonElement); recConvertConfigurationTreeToJsonTree((JsonObject) newJsonElement, configurationElement); } else if (configurationElement.isConfigurationObject()) { if (configurationElement.getValue() instanceof JsonConfigurationValue) { JsonElement newJsonElement = ((JsonConfigurationValue) configurationElement.getValue()).getJsonElement(); parentJsonObject.add(configurationElement.getName(), newJsonElement); } } } }