@Override protected void saveInternal(ConfigurationNode node, Writer writer) throws IOException { if (!node.hasMapChildren()) { if (node.getValue() == null) { writer.write(SYSTEM_LINE_SEPARATOR); return; } else { throw new IOException("HOCON cannot write nodes not in map format!"); } } final ConfigValue value = fromValue(node); final String renderedValue = value.render(render); writer.write(renderedValue); }
@Override protected void saveInternal(ConfigurationNode node, Writer writer) throws IOException { if (!node.hasMapChildren()) { if (node.getValue() == null) { writer.write(SYSTEM_LINE_SEPARATOR); return; } else { throw new IOException("HOCON cannot write nodes not in map format!"); } } final ConfigValue value = fromValue(node); final String renderedValue = value.render(render); writer.write(renderedValue); }
private static ConfigValue fromValue(ConfigurationNode node) { ConfigValue ret; if (node.hasMapChildren()) { Map<String, ConfigValue> children = node.getOptions().getMapFactory().create(); for (Map.Entry<Object, ? extends ConfigurationNode> ent : node.getChildrenMap().entrySet()) { children.put(String.valueOf(ent.getKey()), fromValue(ent.getValue())); } ret = newConfigObject(children); } else if (node.hasListChildren()) { List<ConfigValue> children = new ArrayList<>(); for (ConfigurationNode ent : node.getChildrenList()) { children.add(fromValue(ent)); } ret = newConfigList(children); } else { ret = ConfigValueFactory.fromAnyRef(node.getValue(), "configurate-hocon"); } if (node instanceof CommentedConfigurationNode) { CommentedConfigurationNode commentedNode = ((CommentedConfigurationNode) node); final ConfigValue finalRet = ret; ret = commentedNode.getComment().map(comment -> finalRet.withOrigin(finalRet.origin().withComments(LINE_SPLITTER.splitToList(comment)))).orElse(ret); } return ret; }
private ConfigValue fromValue(ConfigurationNode node) { ConfigValue ret; if (node.hasMapChildren()) { Map<String, ConfigValue> children = node.getOptions().getMapFactory().create(); for (Map.Entry<Object, ? extends ConfigurationNode> ent : node.getChildrenMap().entrySet()) { children.put(String.valueOf(ent.getKey()), fromValue(ent.getValue())); } ret = newConfigObject(children); } else if (node.hasListChildren()) { List<ConfigValue> children = new ArrayList<>(); for (ConfigurationNode ent : node.getChildrenList()) { children.add(fromValue(ent)); } ret = newConfigList(children); } else { ret = ConfigValueFactory.fromAnyRef(node.getValue(), "configurate-hocon"); } if (node instanceof CommentedConfigurationNode) { CommentedConfigurationNode commentedNode = ((CommentedConfigurationNode) node); final ConfigValue finalRet = ret; ret = commentedNode.getComment().map(comment -> finalRet.withOrigin(finalRet.origin().withComments(LINE_SPLITTER.splitToList(comment)))).orElse(ret); } return ret; }