Fix YamlConfiguration not dumping comments

Not sure when it broke, but now it's fixed.
This commit is contained in:
Christian Koop 2022-11-16 02:02:09 +01:00
parent 404a94c307
commit e7da328dc6
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3
2 changed files with 6 additions and 2 deletions

View File

@ -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<String, Supplier<String>> nodeComments;
public YamlCommentRepresenter(Map<String, Supplier<String>> nodeComments) {
public YamlCommentRepresenter(DumperOptions dumperOptions, Map<String, Supplier<String>> nodeComments) {
super(dumperOptions);
this.nodeComments = nodeComments;
}

View File

@ -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);