From e7da328dc6789dcb838176c207f174b05f167841 Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Wed, 16 Nov 2022 02:02:09 +0100 Subject: [PATCH] Fix YamlConfiguration not dumping comments Not sure when it broke, but now it's fixed. --- .../core/configuration/yaml/YamlCommentRepresenter.java | 4 +++- .../songoda/core/configuration/yaml/YamlConfiguration.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Core/src/main/java/com/songoda/core/configuration/yaml/YamlCommentRepresenter.java b/Core/src/main/java/com/songoda/core/configuration/yaml/YamlCommentRepresenter.java index 0c09f4e8..8bf4e4c9 100644 --- a/Core/src/main/java/com/songoda/core/configuration/yaml/YamlCommentRepresenter.java +++ b/Core/src/main/java/com/songoda/core/configuration/yaml/YamlCommentRepresenter.java @@ -1,5 +1,6 @@ package com.songoda.core.configuration.yaml; +import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.comments.CommentLine; import org.yaml.snakeyaml.comments.CommentType; import org.yaml.snakeyaml.events.CommentEvent; @@ -16,7 +17,8 @@ import java.util.function.Supplier; public class YamlCommentRepresenter extends Representer { private final Map> nodeComments; - public YamlCommentRepresenter(Map> nodeComments) { + public YamlCommentRepresenter(DumperOptions dumperOptions, Map> nodeComments) { + super(dumperOptions); this.nodeComments = nodeComments; } diff --git a/Core/src/main/java/com/songoda/core/configuration/yaml/YamlConfiguration.java b/Core/src/main/java/com/songoda/core/configuration/yaml/YamlConfiguration.java index 86f2bf58..286eebe5 100644 --- a/Core/src/main/java/com/songoda/core/configuration/yaml/YamlConfiguration.java +++ b/Core/src/main/java/com/songoda/core/configuration/yaml/YamlConfiguration.java @@ -48,7 +48,7 @@ public class YamlConfiguration implements IConfiguration, HeaderCommentable, Nod this.nodeComments = Objects.requireNonNull(nodeComments); this.yamlDumperOptions = createDefaultYamlDumperOptions(); - this.yamlCommentRepresenter = new YamlCommentRepresenter(this.nodeComments); + this.yamlCommentRepresenter = new YamlCommentRepresenter(this.yamlDumperOptions, this.nodeComments); this.yaml = createDefaultYaml(this.yamlDumperOptions, this.yamlCommentRepresenter); } @@ -275,6 +275,8 @@ public class YamlConfiguration implements IConfiguration, HeaderCommentable, Nod protected static DumperOptions createDefaultYamlDumperOptions() { DumperOptions dumperOptions = new DumperOptions(); + dumperOptions.setProcessComments(true); + dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); dumperOptions.setIndentWithIndicator(true); dumperOptions.setIndicatorIndent(2);