Skip to content

Commit 68975fd

Browse files
authored
Properties parse fix (#207)
1 parent 8f52432 commit 68975fd

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

config/config-common/src/main/java/ru/tinkoff/kora/config/common/factory/MapConfigFactory.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,27 @@ public static Config fromProperties(ConfigOrigin origin, Properties properties)
8787
}
8888
} else {
8989
var field = (PathElement.Key) element;
90+
if (!(currentObject instanceof Map<?, ?>)) {
91+
var prev = (Object) map;
92+
for (int j = 0; j < i - 1; j++) {
93+
if (parts.get(j) instanceof PathElement.Key k) {
94+
prev = ((Map<String, Object>) prev).get(k.name());
95+
} else if (parts.get(j) instanceof PathElement.Index index) {
96+
prev = ((List<Object>) prev).get(index.index());
97+
} else {
98+
throw new IllegalStateException();
99+
}
100+
}
101+
var prevPath = parts.get(i - 1);
102+
currentObject = new LinkedHashMap<String, Object>();
103+
if (prevPath instanceof PathElement.Key k) {
104+
((Map<String, Object>) prev).put(k.name(), currentObject);
105+
} else if (prevPath instanceof PathElement.Index index) {
106+
((List<Object>) prev).set(index.index(), currentObject);
107+
} else {
108+
throw new IllegalStateException();
109+
}
110+
}
90111
var object = (Map<String, Object>) currentObject;
91112
var currentValue = object.get(field.name());
92113
if (currentValue == null) {
@@ -105,7 +126,7 @@ public static Config fromProperties(ConfigOrigin origin, Properties properties)
105126
} else {
106127
if (i + 1 < parts.size()) {
107128
currentObject = currentValue;
108-
} else {
129+
} else if (!(currentValue instanceof Map<?, ?>)) {
109130
object.put(field.name(), value);
110131
}
111132
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package ru.tinkoff.kora.config.common;
2+
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.Test;
5+
6+
7+
class CommonConfigModuleTest {
8+
@Test
9+
void testSystemProperties() {
10+
Assertions.assertNotNull(new CommonConfigModule() {}.systemProperties());
11+
System.out.println(new CommonConfigModule() {}.systemProperties());
12+
}
13+
}

0 commit comments

Comments
 (0)