diff --git a/sources/yaml/src/main/java/io/smallrye/config/source/yaml/YamlConfigSource.java b/sources/yaml/src/main/java/io/smallrye/config/source/yaml/YamlConfigSource.java index 4f017898f..74f801246 100644 --- a/sources/yaml/src/main/java/io/smallrye/config/source/yaml/YamlConfigSource.java +++ b/sources/yaml/src/main/java/io/smallrye/config/source/yaml/YamlConfigSource.java @@ -1,21 +1,16 @@ package io.smallrye.config.source.yaml; -import static java.util.Collections.singletonMap; - import java.io.IOException; import java.io.InputStream; import java.io.UncheckedIOException; import java.net.URL; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.TreeMap; import java.util.function.Function; -import java.util.stream.Collectors; import org.eclipse.microprofile.config.spi.ConfigSource; -import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.LoaderOptions; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.SafeConstructor; @@ -36,14 +31,6 @@ public class YamlConfigSource extends MapBackedConfigSource { private static final String NAME_PREFIX = "YamlConfigSource[source="; private static final int ORDINAL = ConfigSource.DEFAULT_ORDINAL + 10; - private static final Yaml DUMPER; - - static { - final DumperOptions dumperOptions = new DumperOptions(); - dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.FLOW); - dumperOptions.setDefaultScalarStyle(DumperOptions.ScalarStyle.FOLDED); - DUMPER = new Yaml(dumperOptions); - } public YamlConfigSource(String name, Map source, int ordinal) { super(name, source, ordinal, false); @@ -140,8 +127,7 @@ private static void flattenYaml(String path, Map source, Map) value, target, false); } else if (value instanceof List) { - final List list = (List) value; - flattenList(key, list, target); + List list = (List) value; for (int i = 0; i < list.size(); i++) { flattenYaml(key, Collections.singletonMap("[" + i + "]", list.get(i)), target, true); } @@ -153,40 +139,6 @@ private static void flattenYaml(String path, Map source, Map source, Map target) { - boolean mixed = false; - List flatten = new ArrayList<>(); - for (Object value : source) { - if (value instanceof String || value instanceof Boolean) { - flatten.add(value.toString()); - } else if (value != null) { - mixed = true; - break; - } - } - - if (!mixed) { - target.put(key, flatten.stream().map(value -> { - StringBuilder sb = new StringBuilder(); - escapeCommas(sb, value, 1); - return sb.toString(); - }).collect(Collectors.joining(","))); - } - } - - private static void escapeCommas(StringBuilder b, String src, int escapeLevel) { - int cp; - for (int i = 0; i < src.length(); i += Character.charCount(cp)) { - cp = src.codePointAt(i); - if (cp == '\\' || cp == ',') { - for (int j = 0; j < escapeLevel; j++) { - b.append('\\'); - } - } - b.appendCodePoint(cp); - } - } - /** * Override some yaml constructors, so that the value written in the flatten result is more alike with the * source. For instance, timestamps may be written in a completely different format which prevents converters to diff --git a/sources/yaml/src/test/java/io/smallrye/config/source/yaml/ArrayTest.java b/sources/yaml/src/test/java/io/smallrye/config/source/yaml/ArrayTest.java index 39f32960e..32baa681b 100644 --- a/sources/yaml/src/test/java/io/smallrye/config/source/yaml/ArrayTest.java +++ b/sources/yaml/src/test/java/io/smallrye/config/source/yaml/ArrayTest.java @@ -43,7 +43,6 @@ void nullValue() { + " - ~\n")) .build(); - assertEquals("something,1,true", config.getRawValue("foo")); assertEquals("something", config.getRawValue("foo[0]")); assertEquals("1", config.getRawValue("foo[1]")); assertEquals("true", config.getRawValue("foo[2]")); diff --git a/sources/yaml/src/test/java/io/smallrye/config/source/yaml/BasicTest.java b/sources/yaml/src/test/java/io/smallrye/config/source/yaml/BasicTest.java index c9caebcf5..83d83eb40 100644 --- a/sources/yaml/src/test/java/io/smallrye/config/source/yaml/BasicTest.java +++ b/sources/yaml/src/test/java/io/smallrye/config/source/yaml/BasicTest.java @@ -41,7 +41,9 @@ void listValue() { ConfigSource src = new YamlConfigSource("Yaml", yaml); - assertEquals("cat,dog,chicken", src.getValue("foo.bar")); + assertEquals("cat", src.getValue("foo.bar[0]")); + assertEquals("dog", src.getValue("foo.bar[1]")); + assertEquals("chicken", src.getValue("foo.bar[2]")); } @Test diff --git a/sources/yaml/src/test/java/io/smallrye/config/source/yaml/YamlConfigSourceTest.java b/sources/yaml/src/test/java/io/smallrye/config/source/yaml/YamlConfigSourceTest.java index 9c1a73d66..41d7739ce 100644 --- a/sources/yaml/src/test/java/io/smallrye/config/source/yaml/YamlConfigSourceTest.java +++ b/sources/yaml/src/test/java/io/smallrye/config/source/yaml/YamlConfigSourceTest.java @@ -160,7 +160,6 @@ void propertyNames() { assertTrue(propertyNames.contains("quarkus.http.port")); assertTrue(propertyNames.contains("quarkus.http.ssl-port")); - assertTrue(propertyNames.contains("quarkus.http.ssl.protocols")); assertTrue(propertyNames.contains("quarkus.http.ssl.protocols[0]")); assertNotNull(config.getRawValue("quarkus.http.ssl.protocols[0]")); }