Skip to content

Commit

Permalink
Fallback to inline Map conversion instead of being the primary option
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez committed Mar 12, 2024
1 parent cce0c4e commit 8cbe045
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -463,16 +463,12 @@ public <K, V> Optional<Map<K, V>> getOptionalValues(String name, Converter<K> ke

public <K, V> Optional<Map<K, V>> getOptionalValues(String name, Converter<K> keyConverter, Converter<V> valueConverter,
IntFunction<Map<K, V>> mapFactory) {
Optional<Map<K, V>> optionalValue = getOptionalValue(name, newMapConverter(keyConverter, valueConverter, mapFactory));
if (optionalValue.isPresent()) {
return optionalValue;
}

Map<String, String> mapKeys = getMapKeys(name);
if (mapKeys.isEmpty()) {
return Optional.empty();
if (!mapKeys.isEmpty()) {
return Optional.of(getValues(name, keyConverter, valueConverter, mapFactory));
}
return Optional.of(getValues(name, keyConverter, valueConverter, mapFactory));

return getOptionalValue(name, newMapConverter(keyConverter, valueConverter, mapFactory));
}

public <K, V, C extends Collection<V>> Optional<Map<K, C>> getOptionalValues(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2569,4 +2569,28 @@ void ignorePathsRecursive() {
@ConfigMapping(prefix = "ignore")
interface IgnorePathsRecursive {
}

@Test
void nestedLeafsMaps() {
SmallRyeConfig config = new SmallRyeConfigBuilder()
.withSources(config(
"maps.one.two", "value",
"maps.one.two.three", "value"))
.withMapping(NestedLeadfsMaps.class)
.build();

NestedLeadfsMaps mapping = config.getConfigMapping(NestedLeadfsMaps.class);

assertEquals("value", mapping.doubleMap().get("one").get("two"));
assertEquals("value", mapping.tripleMap().get("one").get("two").get("three"));
}

@ConfigMapping(prefix = "maps")
interface NestedLeadfsMaps {
@WithParentName
Map<String, Map<String, String>> doubleMap();

@WithParentName
Map<String, Map<String, Map<String, String>>> tripleMap();
}
}

0 comments on commit 8cbe045

Please sign in to comment.