From 5ee9ca01f70471aeeaf8fb99777eb33fd14d06ce Mon Sep 17 00:00:00 2001 From: Roberto Cortez Date: Fri, 31 Mar 2023 13:52:30 +0100 Subject: [PATCH] Also ignore nested roots, when ignoring a path (#917) --- .../io/smallrye/config/ConfigMappingProvider.java | 4 ++++ .../smallrye/config/ConfigMappingInterfaceTest.java | 13 +++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/implementation/src/main/java/io/smallrye/config/ConfigMappingProvider.java b/implementation/src/main/java/io/smallrye/config/ConfigMappingProvider.java index 08432e98f..4ed3f15a8 100644 --- a/implementation/src/main/java/io/smallrye/config/ConfigMappingProvider.java +++ b/implementation/src/main/java/io/smallrye/config/ConfigMappingProvider.java @@ -100,6 +100,10 @@ final class ConfigMappingProvider implements Serializable { } static void ignoreRecursively(KeyMap> root) { + if (root.getRootValue() == null) { + root.putRootValue(DO_NOTHING); + } + if (root.getAny() == null) { root.putAny(IGNORE_EVERYTHING); } else { diff --git a/implementation/src/test/java/io/smallrye/config/ConfigMappingInterfaceTest.java b/implementation/src/test/java/io/smallrye/config/ConfigMappingInterfaceTest.java index 871929118..74b5bd042 100644 --- a/implementation/src/test/java/io/smallrye/config/ConfigMappingInterfaceTest.java +++ b/implementation/src/test/java/io/smallrye/config/ConfigMappingInterfaceTest.java @@ -1650,9 +1650,10 @@ void ignoreNestedUnknown() { .withSources(config("ignore.nested.nested.value", "value", "ignore.nested.nested.ignore", "ignore")) .withSources(config("ignore.nested.optional.value", "value", "ignore.nested.optional.ignore", "ignore")) .withSources(config("ignore.nested.list[0].value", "value", "ignore.nested.list[0].ignore", "ignore")) - .withSources(config("ignore.nested.map.key", "value", "ignore.nested.map.ignored.ignored", "ignore")) + .withSources(config("ignore.nested.map.key.value", "value", "ignore.nested.map.ignored.ignored", "ignore")) + .withSources(config("ignore.nested.key.value", "parent", "ignore.nested.ignored.ignored", "ignore")) .withSources(config("ignore.nested.ignore.ignore", "ignore")) - .withMappingIgnore("ignore.nested.**") + .withMappingIgnore("ignore.**") .build(); IgnoreNestedUnknown mapping = config.getConfigMapping(IgnoreNestedUnknown.class); @@ -1662,7 +1663,8 @@ void ignoreNestedUnknown() { assertTrue(mapping.optional().isPresent()); assertEquals("value", mapping.optional().get().value()); assertEquals("value", mapping.list().get(0).value()); - assertEquals("value", mapping.map().get("key")); + assertEquals("value", mapping.map().get("key").value()); + assertEquals("parent", mapping.mapParent().get("key").value()); } @ConfigMapping(prefix = "ignore.nested") @@ -1675,7 +1677,10 @@ interface IgnoreNestedUnknown { List list(); - Map map(); + Map map(); + + @WithParentName + Map mapParent(); interface Nested { String value();