diff --git a/config/config-common/src/main/java/ru/tinkoff/kora/config/common/factory/MapConfigFactory.java b/config/config-common/src/main/java/ru/tinkoff/kora/config/common/factory/MapConfigFactory.java index 5ec3c9ce8..bffb3255d 100644 --- a/config/config-common/src/main/java/ru/tinkoff/kora/config/common/factory/MapConfigFactory.java +++ b/config/config-common/src/main/java/ru/tinkoff/kora/config/common/factory/MapConfigFactory.java @@ -87,6 +87,27 @@ public static Config fromProperties(ConfigOrigin origin, Properties properties) } } else { var field = (PathElement.Key) element; + if (!(currentObject instanceof Map)) { + var prev = (Object) map; + for (int j = 0; j < i - 1; j++) { + if (parts.get(j) instanceof PathElement.Key k) { + prev = ((Map) prev).get(k.name()); + } else if (parts.get(j) instanceof PathElement.Index index) { + prev = ((List) prev).get(index.index()); + } else { + throw new IllegalStateException(); + } + } + var prevPath = parts.get(i - 1); + currentObject = new LinkedHashMap(); + if (prevPath instanceof PathElement.Key k) { + ((Map) prev).put(k.name(), currentObject); + } else if (prevPath instanceof PathElement.Index index) { + ((List) prev).set(index.index(), currentObject); + } else { + throw new IllegalStateException(); + } + } var object = (Map) currentObject; var currentValue = object.get(field.name()); if (currentValue == null) { @@ -105,7 +126,7 @@ public static Config fromProperties(ConfigOrigin origin, Properties properties) } else { if (i + 1 < parts.size()) { currentObject = currentValue; - } else { + } else if (!(currentValue instanceof Map)) { object.put(field.name(), value); } } diff --git a/config/config-common/src/test/java/ru/tinkoff/kora/config/common/CommonConfigModuleTest.java b/config/config-common/src/test/java/ru/tinkoff/kora/config/common/CommonConfigModuleTest.java new file mode 100644 index 000000000..a959f94c0 --- /dev/null +++ b/config/config-common/src/test/java/ru/tinkoff/kora/config/common/CommonConfigModuleTest.java @@ -0,0 +1,13 @@ +package ru.tinkoff.kora.config.common; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + + +class CommonConfigModuleTest { + @Test + void testSystemProperties() { + Assertions.assertNotNull(new CommonConfigModule() {}.systemProperties()); + System.out.println(new CommonConfigModule() {}.systemProperties()); + } +}