From 5ffc01f256c41d63df57297ff6150aec9ba07a25 Mon Sep 17 00:00:00 2001 From: Matthes Rieke Date: Fri, 21 Jul 2023 11:24:57 +0200 Subject: [PATCH] raise snakeyaml version and apply required changes --- pom.xml | 4 ++-- .../github/autermann/yaml/YamlNodeRepresenter.java | 13 +++++++------ .../yaml/construct/YamlNodeConstructor.java | 6 +++--- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 7dda3be..80b58d2 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ com.github.autermann yaml - 1.0.4-SNAPSHOT + 2.0.0-SNAPSHOT jar YAML API @@ -84,7 +84,7 @@ org.yaml snakeyaml - 1.15 + 2.0 diff --git a/src/main/java/com/github/autermann/yaml/YamlNodeRepresenter.java b/src/main/java/com/github/autermann/yaml/YamlNodeRepresenter.java index b8c7263..0534101 100644 --- a/src/main/java/com/github/autermann/yaml/YamlNodeRepresenter.java +++ b/src/main/java/com/github/autermann/yaml/YamlNodeRepresenter.java @@ -85,6 +85,7 @@ public YamlNodeRepresenter() { * @param options the dumper options */ public YamlNodeRepresenter(DumperOptions options) { + super(options); Objects.requireNonNull(options); this.timeEncoding = ISODateTimeFormat.dateTime(); this.binaryEncoding = BaseEncoding.base64() @@ -162,9 +163,9 @@ private Node delegate(Tag tag, Object value) { private MappingNode delegate(Tag tag, Iterable> mapping) { List value = new LinkedList<>(); - MappingNode node = new MappingNode(tag, value, null); + MappingNode node = new MappingNode(tag, value, FlowStyle.AUTO); representedObjects.put(objectToRepresent, node); - boolean bestStyle = true; + FlowStyle bestStyle = FlowStyle.AUTO; for (Map.Entry entry : mapping) { Node nodeKey = representData(entry.getKey()); Node nodeValue = representData(entry.getValue()); @@ -174,7 +175,7 @@ private MappingNode delegate(Tag tag, } if (getDefaultFlowStyle() != FlowStyle.AUTO) { - node.setFlowStyle(getDefaultFlowStyle().getStyleBoolean()); + node.setFlowStyle(getDefaultFlowStyle()); } else { node.setFlowStyle(bestStyle); } @@ -189,11 +190,11 @@ private MappingNode delegate(Tag tag, * * @return the new best style */ - private boolean bestStyle(Node node, boolean bestStyle) { + private FlowStyle bestStyle(Node node, FlowStyle bestStyle) { if (node instanceof ScalarNode) { ScalarNode scalar = (ScalarNode) node; - if (scalar.getStyle() == null) { - return false; + if (scalar.getScalarStyle() == null) { + return FlowStyle.AUTO; } } return bestStyle; diff --git a/src/main/java/com/github/autermann/yaml/construct/YamlNodeConstructor.java b/src/main/java/com/github/autermann/yaml/construct/YamlNodeConstructor.java index 384b0a0..3e8bd9f 100644 --- a/src/main/java/com/github/autermann/yaml/construct/YamlNodeConstructor.java +++ b/src/main/java/com/github/autermann/yaml/construct/YamlNodeConstructor.java @@ -23,6 +23,7 @@ import org.joda.time.format.DateTimeFormatter; import org.joda.time.format.ISODateTimeFormat; import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.LoaderOptions; import org.yaml.snakeyaml.constructor.Construct; import org.yaml.snakeyaml.constructor.SafeConstructor; import org.yaml.snakeyaml.nodes.MappingNode; @@ -87,6 +88,7 @@ public YamlNodeConstructor(YamlNodeFactory nodeFactory) { */ public YamlNodeConstructor(YamlNodeFactory nodeFactory, DumperOptions options) { + super(new LoaderOptions()); this.options = Objects.requireNonNull(options); this.nodeFactory = Objects.requireNonNull(nodeFactory); register(); @@ -320,13 +322,11 @@ public List constructSequence(SequenceNode node) { * Constructs a scalar. * * @param node the node to construct from - * * @return the constructed scalar - * * @see SafeConstructor#constructScalar(ScalarNode) */ @Override - public Object constructScalar(ScalarNode node) { + public String constructScalar(ScalarNode node) { return super.constructScalar(node); } }