Skip to content

Commit

Permalink
Properties parse fix (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
Squiry authored Jul 19, 2023
1 parent 8f52432 commit 68975fd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object>) prev).get(k.name());
} else if (parts.get(j) instanceof PathElement.Index index) {
prev = ((List<Object>) prev).get(index.index());
} else {
throw new IllegalStateException();
}
}
var prevPath = parts.get(i - 1);
currentObject = new LinkedHashMap<String, Object>();
if (prevPath instanceof PathElement.Key k) {
((Map<String, Object>) prev).put(k.name(), currentObject);
} else if (prevPath instanceof PathElement.Index index) {
((List<Object>) prev).set(index.index(), currentObject);
} else {
throw new IllegalStateException();
}
}
var object = (Map<String, Object>) currentObject;
var currentValue = object.get(field.name());
if (currentValue == null) {
Expand All @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit 68975fd

Please sign in to comment.