From d7d2880c44416c588bb82136e26a1642eb30b373 Mon Sep 17 00:00:00 2001 From: marhali Date: Sun, 19 Feb 2023 15:23:28 +0100 Subject: [PATCH] replace yaml mapping with own implementation to fix pluginVerifierTask --- CHANGELOG.md | 1 + .../io/parser/yaml/YamlArrayMapper.java | 15 +- .../easyi18n/io/parser/yaml/YamlMapper.java | 40 ++- .../io/parser/yaml/YamlParserStrategy.java | 37 ++- .../thito/nodeflow/config/ListSection.java | 227 ------------------ .../thito/nodeflow/config/MapSection.java | 78 ------ .../java/thito/nodeflow/config/Section.java | 221 ----------------- .../easyi18n/mapper/YamlMapperTest.java | 69 +++--- 8 files changed, 83 insertions(+), 605 deletions(-) delete mode 100644 src/main/java/thito/nodeflow/config/ListSection.java delete mode 100644 src/main/java/thito/nodeflow/config/MapSection.java delete mode 100644 src/main/java/thito/nodeflow/config/Section.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 11f585d..662067f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Dropped support for IDE versions older than 2022.2 - Updated dependencies - Removed deprecated API access (TranslatorToolWindowFactory) +- Replaced YAML mapping with own implementation ### Fixed - Support for all 2023.1 builds (231.*) diff --git a/src/main/java/de/marhali/easyi18n/io/parser/yaml/YamlArrayMapper.java b/src/main/java/de/marhali/easyi18n/io/parser/yaml/YamlArrayMapper.java index 4ed9af2..6bd33b7 100644 --- a/src/main/java/de/marhali/easyi18n/io/parser/yaml/YamlArrayMapper.java +++ b/src/main/java/de/marhali/easyi18n/io/parser/yaml/YamlArrayMapper.java @@ -2,20 +2,17 @@ package de.marhali.easyi18n.io.parser.yaml; import de.marhali.easyi18n.io.parser.ArrayMapper; -import thito.nodeflow.config.ListSection; +import java.util.ArrayList; +import java.util.List; -/** - * Map for yaml array values. - * @author marhali - */ public class YamlArrayMapper extends ArrayMapper { - public static String read(ListSection list) { + public static String read(List list) { return read(list.iterator(), Object::toString); } - public static ListSection write(String concat) { - ListSection list = new ListSection(); + public static List write(String concat) { + List list = new ArrayList<>(); write(concat, list::add); return list; } -} \ No newline at end of file +} diff --git a/src/main/java/de/marhali/easyi18n/io/parser/yaml/YamlMapper.java b/src/main/java/de/marhali/easyi18n/io/parser/yaml/YamlMapper.java index 09e92da..78709b6 100644 --- a/src/main/java/de/marhali/easyi18n/io/parser/yaml/YamlMapper.java +++ b/src/main/java/de/marhali/easyi18n/io/parser/yaml/YamlMapper.java @@ -7,31 +7,25 @@ import de.marhali.easyi18n.util.StringUtil; import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang.math.NumberUtils; -import thito.nodeflow.config.ListSection; -import thito.nodeflow.config.MapSection; -import thito.nodeflow.config.Section; - +import java.util.HashMap; +import java.util.List; import java.util.Map; -/** - * Mapper for mapping yaml files into translation nodes and backwards. - * @author marhali - */ public class YamlMapper { - - public static void read(String locale, Section section, TranslationNode node) { - for(String key : section.getKeys()) { - Object value = section.getInScope(key).get(); + @SuppressWarnings("unchecked") + public static void read(String locale, Map section, TranslationNode node) { + for(String key : section.keySet()) { + Object value = section.get(key); TranslationNode childNode = node.getOrCreateChildren(key); - if(value instanceof MapSection) { - // Nested element - run recursively - read(locale, (MapSection) value, childNode); + if(value instanceof Map) { + // Nested element run recursively + read(locale, (Map) value, childNode); } else { TranslationValue translation = childNode.getValue(); - String content = value instanceof ListSection - ? YamlArrayMapper.read((ListSection) value) + String content = value instanceof List + ? YamlArrayMapper.read((List) value) : StringUtil.escapeControls(String.valueOf(value), true); translation.put(locale, content); @@ -40,17 +34,17 @@ public class YamlMapper { } } - public static void write(String locale, Section section, TranslationNode node) { + public static void write(String locale, Map section, TranslationNode node) { for(Map.Entry entry : node.getChildren().entrySet()) { String key = entry.getKey(); TranslationNode childNode = entry.getValue(); if(!childNode.isLeaf()) { // Nested node - run recursively - MapSection childSection = new MapSection(); + Map childSection = new HashMap<>(); write(locale, childSection, childNode); if(childSection.size() > 0) { - section.setInScope(key, childSection); + section.put(key, childSection); } } else { TranslationValue translation = childNode.getValue(); @@ -58,11 +52,11 @@ public class YamlMapper { if(content != null) { if(YamlArrayMapper.isArray(content)) { - section.setInScope(key, YamlArrayMapper.write(content)); + section.put(key, YamlArrayMapper.write(content)); } else if(NumberUtils.isNumber(content)) { - section.setInScope(key, NumberUtils.createNumber(content)); + section.put(key, NumberUtils.createNumber(content)); } else { - section.setInScope(key, StringEscapeUtils.unescapeJava(content)); + section.put(key, StringEscapeUtils.unescapeJava(content)); } } } diff --git a/src/main/java/de/marhali/easyi18n/io/parser/yaml/YamlParserStrategy.java b/src/main/java/de/marhali/easyi18n/io/parser/yaml/YamlParserStrategy.java index 8944255..faa70e8 100644 --- a/src/main/java/de/marhali/easyi18n/io/parser/yaml/YamlParserStrategy.java +++ b/src/main/java/de/marhali/easyi18n/io/parser/yaml/YamlParserStrategy.java @@ -10,20 +10,32 @@ import de.marhali.easyi18n.model.TranslationNode; import de.marhali.easyi18n.settings.ProjectSettings; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.error.YAMLException; -import thito.nodeflow.config.MapSection; -import thito.nodeflow.config.Section; import java.io.InputStreamReader; import java.io.Reader; +import java.util.HashMap; +import java.util.Map; -/** - * Yaml / YML file format parser strategy. - * @author marhali - */ public class YamlParserStrategy extends ParserStrategy { + private static DumperOptions dumperOptions() { + DumperOptions options = new DumperOptions(); + + options.setIndent(2); + options.setAllowUnicode(true); + options.setPrettyFlow(true); + options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); + + return options; + } + + private static final Yaml YAML = new Yaml(dumperOptions()); + public YamlParserStrategy(@NotNull ProjectSettings settings) { super(settings); } @@ -36,11 +48,11 @@ public class YamlParserStrategy extends ParserStrategy { TranslationNode targetNode = super.getOrCreateTargetNode(file, data); try(Reader reader = new InputStreamReader(vf.getInputStream(), vf.getCharset())) { - Section input; + Map input; try { - input = Section.parseToMap(reader); - } catch (YAMLException ex) { + input = YAML.load(reader); + } catch(YAMLException ex) { throw new SyntaxException(ex.getMessage(), file); } @@ -49,11 +61,12 @@ public class YamlParserStrategy extends ParserStrategy { } @Override - public @NotNull String write(@NotNull TranslationData data, @NotNull TranslationFile file) throws Exception { + public @Nullable String write(@NotNull TranslationData data, @NotNull TranslationFile file) throws Exception { TranslationNode targetNode = super.getTargetNode(data, file); - Section output = new MapSection(); + Map output = new HashMap<>(); YamlMapper.write(file.getLocale(), output, targetNode); - return Section.toString(output); + + return YAML.dumpAsMap(output); } } diff --git a/src/main/java/thito/nodeflow/config/ListSection.java b/src/main/java/thito/nodeflow/config/ListSection.java deleted file mode 100644 index d82b65b..0000000 --- a/src/main/java/thito/nodeflow/config/ListSection.java +++ /dev/null @@ -1,227 +0,0 @@ -package thito.nodeflow.config; - -import java.util.*; -import java.util.stream.*; - -public class ListSection extends ArrayList implements Section { - private Section parent; - private String name; - - public ListSection() { - super(); - } - - public ListSection(Collection c) { - super(); - addAll(c); - } - - public void setParent(Section parent, String name) { - this.parent = parent; - this.name = name; - } - - @Override - public String getName() { - if (name == null && parent != null) { - if (parent instanceof ListSection) { - return String.valueOf(((ListSection) parent).indexOf(this)); - } - if (parent instanceof MapSection) { - return ((MapSection) parent).entrySet().stream().filter(e -> Objects.equals(e.getValue(), this)) - .findAny().map(Map.Entry::getKey).orElse(null); - } - } - return name; - } - - public Optional getObject(int index) { - return index >= 0 && index < size() ? Optional.ofNullable(get(index)) : Optional.empty(); - } - - @Override - public Section getParent() { - return parent; - } - - @Override - public Set getKeys() { - return IntStream.range(0, size()).mapToObj(String::valueOf).collect(Collectors.toSet()); - } - - @Override - public Optional getInScope(String key) { - try { - return Optional.ofNullable(get(Integer.parseInt(key))); - } catch (Throwable t) { - } - return Optional.empty(); - } - - @Override - public void setInScope(String key, Object value) { - try { - set(Integer.parseInt(key), value); - } catch (Throwable t) { - } - } - - @Override - public Object set(int index, Object element) { - element = Section.wrap(element); - if (element instanceof Section) element = Section.wrapParent(this, null, (Section) element); - return super.set(index, element); - } - - @Override - public boolean add(Object o) { - o = Section.wrap(o); - if (o instanceof Section) o = Section.wrapParent(this, null, (Section) o); - return super.add(o); - } - - @Override - public void add(int index, Object element) { - element = Section.wrap(element); - if (element instanceof Section) element = Section.wrapParent(this, null, (Section) element); - super.add(index, element); - } - - @Override - public boolean addAll(Collection c) { - c.forEach(o -> add(o)); - return !c.isEmpty(); - } - - @Override - public boolean addAll(int index, Collection c) { - List wrapped = new ArrayList<>(); - c.forEach(obj -> { - Object o = Section.wrap(obj); - if (o instanceof Section) o = Section.wrapParent(this, null, (Section) o); - wrapped.add(o); - }); - return super.addAll(index, wrapped); - } - - @Override - public String toString() { - return Section.toString(this); - } - - public > Optional getEnum(int index, Class clz) { - return getObject(index).map(o -> { - try { - return Enum.valueOf(clz, String.valueOf(o)); - } catch (Throwable t) { - return null; - } - }); - } - - public Optional getString(int index) { - return getObject(index).map(String::valueOf); - } - - public Optional getInteger(int index) { - return getObject(index).map(o -> { - try { - return Integer.valueOf(String.valueOf(o)); - } catch (Throwable t) { - return null; - } - }); - } - - public Optional getDouble(int index) { - return getObject(index).map(o -> { - try { - return Double.valueOf(String.valueOf(o)); - } catch (Throwable t) { - return null; - } - }); - } - - public Optional getLong(int index) { - return getObject(index).map(o -> { - try { - return Long.valueOf(String.valueOf(o)); - } catch (Throwable t) { - return null; - } - }); - } - - public Optional getFloat(int index) { - return getObject(index).map(o -> { - try { - return Float.valueOf(String.valueOf(o)); - } catch (Throwable t) { - return null; - } - }); - } - - public Optional getShort(int index) { - return getObject(index).map(o -> { - try { - return Short.valueOf(String.valueOf(o)); - } catch (Throwable t) { - return null; - } - }); - } - - public Optional getByte(int index) { - return getObject(index).map(o -> { - try { - return Byte.valueOf(String.valueOf(o)); - } catch (Throwable t) { - return null; - } - }); - } - - public Optional getCharacter(int index) { - return getObject(index).map(o -> { - String text = String.valueOf(o); - return text.isEmpty() ? null : text.charAt(0); - }); - } - - public Optional getBoolean(int index) { - return getObject(index).map(o -> { - String text = String.valueOf(o); - return text.equals("true") ? Boolean.TRUE : text.equals("false") ? Boolean.FALSE : null; - }); - } - - public Optional getMap(int index) { - return getObject(index).map(o -> { - if (o instanceof Map) { - if (o instanceof MapSection) return (MapSection) o; - MapSection mapSection = new MapSection((Map) o); - mapSection.setParent(this, null); - return mapSection; - } - return null; - }); - } - - public Optional getList(int index) { - return getObject(index).map(o -> { - if (o instanceof List) { - if (o instanceof ListSection) { - return (ListSection) o; - } - ListSection list = new ListSection((List) o); - list.setParent(this, null); - return list; - } - ListSection list = new ListSection(Collections.singleton(o)); - list.setParent(this, null); - return list; - }); - } -} diff --git a/src/main/java/thito/nodeflow/config/MapSection.java b/src/main/java/thito/nodeflow/config/MapSection.java deleted file mode 100644 index ad3b158..0000000 --- a/src/main/java/thito/nodeflow/config/MapSection.java +++ /dev/null @@ -1,78 +0,0 @@ -package thito.nodeflow.config; - -import org.jetbrains.annotations.Nullable; - -import java.util.*; - -public class MapSection extends HashMap implements Section { - private Section parent; - private String name; - - public MapSection() { - super(); - } - - public MapSection(@Nullable Map m) { - super(); - - if(m != null) { - m.forEach((key, value) -> put(String.valueOf(key), value)); - } - } - - public void setParent(Section parent, String name) { - this.parent = parent; - this.name = name; - } - - @Override - public String getName() { - if (name == null && parent != null) { - if (parent instanceof ListSection) { - return String.valueOf(((ListSection) parent).indexOf(this)); - } - if (parent instanceof MapSection) { - return ((MapSection) parent).entrySet().stream().filter(e -> Objects.equals(e.getValue(), this)) - .findAny().map(Entry::getKey).orElse(null); - } - } - return name; - } - - @Override - public Section getParent() { - return parent; - } - - @Override - public void setInScope(String key, Object value) { - put(key, value); - } - - @Override - public Object put(String key, Object value) { - value = Section.wrap(value); - if (value instanceof Section) value = Section.wrapParent(this, key, (Section) value); - return super.put(key, value); - } - - @Override - public void putAll(Map m) { - m.forEach(this::put); - } - - @Override - public Set getKeys() { - return keySet(); - } - - @Override - public Optional getInScope(String key) { - return Optional.ofNullable(get(key)); - } - - @Override - public String toString() { - return Section.toString(this); - } -} diff --git a/src/main/java/thito/nodeflow/config/Section.java b/src/main/java/thito/nodeflow/config/Section.java deleted file mode 100644 index 3083c63..0000000 --- a/src/main/java/thito/nodeflow/config/Section.java +++ /dev/null @@ -1,221 +0,0 @@ -package thito.nodeflow.config; - -import org.yaml.snakeyaml.*; - -import java.io.*; -import java.util.*; -import java.util.regex.*; - -public interface Section { - String SEPARATOR = "."; - static Object wrap(Object o) { - if (o instanceof Section) return o; - if (o instanceof List) { - return new ListSection((List) o); - } - if (o instanceof Map) { - return new MapSection((Map) o); - } - return o; - } - static String getName(String path) { - String[] split = path.split(Pattern.quote(SEPARATOR)); - return split[split.length - 1]; - } - static Section wrapParent(Section parent, String name, Section current) { - if (current.getParent() != null && current.getParent() != parent) { - if (current instanceof MapSection) { - MapSection mapSection = new MapSection((MapSection) current); - mapSection.setParent(parent, name); - return mapSection; - } - if (current instanceof ListSection) { - ListSection objects = new ListSection((ListSection) current); - objects.setParent(parent, name); - return objects; - } - } else { - if (current instanceof MapSection) { - ((MapSection) current).setParent(parent, name); - } - if (current instanceof ListSection) { - ((ListSection) current).setParent(parent, name); - } - } - return current; - } - static String toString(Section section) { - DumperOptions options = new DumperOptions(); - options.setIndent(2); - options.setAllowUnicode(true); - options.setPrettyFlow(true); - options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); - Yaml yaml = new Yaml(options); - return yaml.dumpAsMap(section); - } - static MapSection parseToMap(Reader reader) { - Yaml yaml = new Yaml(); - return new MapSection(yaml.loadAs(reader, Map.class)); - } - Set getKeys(); - default Set getPaths() { - Set paths = new HashSet<>(); - for (String k : getKeys()) { - Object lookup = getInScope(k).orElse(null); - if (lookup instanceof Section) { - for (String p : ((Section) lookup).getPaths()) { - paths.add(k + "." + p); - } - } - } - return paths; - } - String getName(); - default String getPath() { - StringBuilder path = new StringBuilder(getName()); - Section parent; - while ((parent = getParent()) != null) { - path.insert(0, parent.getName() + SEPARATOR); - } - return path.toString(); - } - Section getParent(); - Optional getInScope(String key); - void setInScope(String key, Object value); - default void set(String path, Object value) { - String[] paths = path.split(Pattern.quote(SEPARATOR)); - Object lookup = this; - for (int i = 0; i < paths.length - 1; i++) { - Section oldLookup = (Section) lookup; - lookup = oldLookup.getInScope(paths[i]).orElse(null); - if (!(lookup instanceof Section)) { - oldLookup.setInScope(paths[i], lookup = new MapSection()); - } - } - if (paths.length > 0) { - ((Section) lookup).setInScope(paths[paths.length - 1], value); - } - } - default Optional getObject(String path) { - String[] paths = path.split(Pattern.quote(SEPARATOR)); - Object lookup = this; - for (String s : paths) { - if (lookup instanceof Section) { - lookup = ((Section) lookup).getInScope(s).orElse(null); - } else { - return Optional.empty(); - } - } - return Optional.ofNullable(lookup); - } - default > Optional getEnum(String path, Class clz) { - return getObject(path).map(o -> { - try { - return Enum.valueOf(clz, String.valueOf(o)); - } catch (Throwable t) { - return null; - } - }); - } - default Optional getString(String path) { - return getObject(path).map(String::valueOf); - } - default Optional getInteger(String path) { - return getObject(path).map(o -> { - try { - return Integer.valueOf(String.valueOf(o)); - } catch (Throwable t) { - return null; - } - }); - } - default Optional getDouble(String path) { - return getObject(path).map(o -> { - try { - return Double.valueOf(String.valueOf(o)); - } catch (Throwable t) { - return null; - } - }); - } - default Optional getLong(String path) { - return getObject(path).map(o -> { - try { - return Long.valueOf(String.valueOf(o)); - } catch (Throwable t) { - return null; - } - }); - } - default Optional getFloat(String path) { - return getObject(path).map(o -> { - try { - return Float.valueOf(String.valueOf(o)); - } catch (Throwable t) { - return null; - } - }); - } - default Optional getShort(String path) { - return getObject(path).map(o -> { - try { - return Short.valueOf(String.valueOf(o)); - } catch (Throwable t) { - return null; - } - }); - } - default Optional getByte(String path) { - return getObject(path).map(o -> { - try { - return Byte.valueOf(String.valueOf(o)); - } catch (Throwable t) { - return null; - } - }); - } - default Optional getCharacter(String path) { - return getObject(path).map(o -> { - String text = String.valueOf(o); - return text.isEmpty() ? null : text.charAt(0); - }); - } - default Optional getBoolean(String path) { - return getObject(path).map(o -> { - String text = String.valueOf(o); - return text.equals("true") ? Boolean.TRUE : text.equals("false") ? Boolean.FALSE : null; - }); - } - default Optional getMap(String path) { - return getObject(path).map(o -> { - if (o instanceof Map) { - if (o instanceof MapSection) return (MapSection) o; - MapSection mapSection = new MapSection((Map) o); - mapSection.setParent(getParent(), Section.getName(path)); - return mapSection; - } - return null; - }); - } - - default boolean isList(String path) { - Optional o = getObject(path); - return o.isPresent() && o.get() instanceof List; - } - - default Optional getList(String path) { - return getObject(path).map(o -> { - if (o instanceof List) { - if (o instanceof ListSection) { - return (ListSection) o; - } - ListSection list = new ListSection((List) o); - list.setParent(this, Section.getName(path)); - return list; - } - ListSection list = new ListSection(Collections.singleton(o)); - list.setParent(getParent(), Section.getName(path)); - return list; - }); - } -} diff --git a/src/test/java/de/marhali/easyi18n/mapper/YamlMapperTest.java b/src/test/java/de/marhali/easyi18n/mapper/YamlMapperTest.java index 9eefe5c..d5fbb03 100644 --- a/src/test/java/de/marhali/easyi18n/mapper/YamlMapperTest.java +++ b/src/test/java/de/marhali/easyi18n/mapper/YamlMapperTest.java @@ -8,51 +8,47 @@ import org.apache.commons.lang.StringEscapeUtils; import org.junit.Assert; -import thito.nodeflow.config.MapSection; -import thito.nodeflow.config.Section; - -import java.util.Arrays; -import java.util.LinkedHashSet; -import java.util.Set; +import java.util.*; /** * Unit tests for {@link YamlMapper}. * @author marhali */ +@SuppressWarnings("unchecked") public class YamlMapperTest extends AbstractMapperTest { @Override public void testNonSorting() { - Section input = new MapSection(); - input.set("zulu", "test"); - input.set("alpha", "test"); - input.set("bravo", "test"); + Map input = new HashMap<>(); + input.put("zulu", "test"); + input.put("alpha", "test"); + input.put("bravo", "test"); TranslationData data = new TranslationData(false); YamlMapper.read("en", input, data.getRootNode()); - Section output = new MapSection(); + Map output = new HashMap<>(); YamlMapper.write("en", output, data.getRootNode()); Set expect = new LinkedHashSet<>(Arrays.asList("zulu", "alpha", "bravo")); - Assert.assertEquals(expect, output.getKeys()); + Assert.assertEquals(expect, output.keySet()); } @Override public void testSorting() { - Section input = new MapSection(); - input.set("zulu", "test"); - input.set("alpha", "test"); - input.set("bravo", "test"); + Map input = new HashMap<>(); + input.put("zulu", "test"); + input.put("alpha", "test"); + input.put("bravo", "test"); TranslationData data = new TranslationData(true); YamlMapper.read("en", input, data.getRootNode()); - Section output = new MapSection(); + Map output = new HashMap<>(); YamlMapper.write("en", output, data.getRootNode()); Set expect = new LinkedHashSet<>(Arrays.asList("alpha", "bravo", "zulu")); - Assert.assertEquals(expect, output.getKeys()); + Assert.assertEquals(expect, output.keySet()); } @Override @@ -61,13 +57,13 @@ public class YamlMapperTest extends AbstractMapperTest { data.setTranslation(new KeyPath("simple"), create(arraySimple)); data.setTranslation(new KeyPath("escaped"), create(arrayEscaped)); - Section output = new MapSection(); + Map output = new HashMap<>(); YamlMapper.write("en", output, data.getRootNode()); - Assert.assertTrue(output.isList("simple")); - Assert.assertEquals(arraySimple, YamlArrayMapper.read(output.getList("simple").get())); - Assert.assertTrue(output.isList("escaped")); - Assert.assertEquals(arrayEscaped, StringEscapeUtils.unescapeJava(YamlArrayMapper.read(output.getList("escaped").get()))); + Assert.assertTrue(output.get("simple") instanceof List); + Assert.assertEquals(arraySimple, YamlArrayMapper.read((List) output.get("simple"))); + Assert.assertTrue(output.get("escaped") instanceof List); + Assert.assertEquals(arrayEscaped, StringEscapeUtils.unescapeJava(YamlArrayMapper.read((List) output.get("escaped")))); TranslationData input = new TranslationData(true); YamlMapper.read("en", output, input.getRootNode()); @@ -81,10 +77,10 @@ public class YamlMapperTest extends AbstractMapperTest { TranslationData data = new TranslationData(true); data.setTranslation(new KeyPath("chars"), create(specialCharacters)); - Section output = new MapSection(); + Map output = new HashMap<>(); YamlMapper.write("en", output, data.getRootNode()); - Assert.assertEquals(specialCharacters, output.getString("chars").get()); + Assert.assertEquals(specialCharacters, output.get("chars")); TranslationData input = new TranslationData(true); YamlMapper.read("en", output, input.getRootNode()); @@ -98,10 +94,13 @@ public class YamlMapperTest extends AbstractMapperTest { TranslationData data = new TranslationData(true); data.setTranslation(new KeyPath("nested", "key", "section"), create("test")); - Section output = new MapSection(); + Map output = new HashMap<>(); YamlMapper.write("en", output, data.getRootNode()); - Assert.assertEquals("test", output.getString("nested.key.section").get()); + Assert.assertTrue(output.containsKey("nested")); + Assert.assertTrue(((Map) output.get("nested")).containsKey("key")); + + Assert.assertEquals("test", ((Map)((Map)output.get("nested")).get("key")).get("section")); TranslationData input = new TranslationData(true); YamlMapper.read("en", output, input.getRootNode()); @@ -114,10 +113,10 @@ public class YamlMapperTest extends AbstractMapperTest { TranslationData data = new TranslationData(true); data.setTranslation(new KeyPath("long.key.with.many.sections"), create("test")); - Section output = new MapSection(); + Map output = new HashMap<>(); YamlMapper.write("en", output, data.getRootNode()); - Assert.assertTrue(output.getKeys().contains("long.key.with.many.sections")); + Assert.assertTrue(output.containsKey("long.key.with.many.sections")); TranslationData input = new TranslationData(true); YamlMapper.read("en", output, input.getRootNode()); @@ -130,10 +129,10 @@ public class YamlMapperTest extends AbstractMapperTest { TranslationData data = new TranslationData(true); data.setTranslation(new KeyPath("space"), create(leadingSpace)); - Section output = new MapSection(); + Map output = new HashMap<>(); YamlMapper.write("en", output, data.getRootNode()); - Assert.assertEquals(leadingSpace, output.getString("space").get()); + Assert.assertEquals(leadingSpace, output.get("space")); TranslationData input = new TranslationData(true); YamlMapper.read("en", output, input.getRootNode()); @@ -146,13 +145,13 @@ public class YamlMapperTest extends AbstractMapperTest { TranslationData data = new TranslationData(true); data.setTranslation(new KeyPath("numbered"), create("15000")); - Section output = new MapSection(); + Map output = new HashMap<>(); YamlMapper.write("en", output, data.getRootNode()); - Assert.assertEquals(15000, output.getInteger("numbered").get().intValue()); + Assert.assertEquals(15000, output.get("numbered")); - Section input = new MapSection(); - input.set("numbered", 143.23); + Map input = new HashMap<>(); + input.put("numbered", 143.23); YamlMapper.read("en", input, data.getRootNode()); Assert.assertEquals("143.23", data.getTranslation(new KeyPath("numbered")).get("en"));