Skip to content

Commit

Permalink
Fix ConfigMappings, Optional in Group in Map. (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez authored Jan 27, 2021
1 parent 54829e1 commit 8e0aa94
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,13 @@ private void processLazyGroupInGroup(ArrayDeque<String> currentPath,
if (primitiveProperty.hasDefaultValue()) {
defaultValues.findOrAdd(currentPath).putRootValue(primitiveProperty.getDefaultValue());
}
} else if (property.isLeaf()) {
LeafProperty leafProperty = property.asLeaf();
} else if (property.isLeaf() && optional) {
LeafProperty leafProperty = property.asOptional().getNestedProperty().asLeaf();
if (leafProperty.hasDefaultValue()) {
defaultValues.findOrAdd(currentPath).putRootValue(leafProperty.getDefaultValue());
}
} else {
LeafProperty leafProperty = property.asOptional().getNestedProperty().asLeaf();
LeafProperty leafProperty = property.asLeaf();
if (leafProperty.hasDefaultValue()) {
defaultValues.findOrAdd(currentPath).putRootValue(leafProperty.getDefaultValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ void optionals() {
put("server.port", "8080");
put("optional", "optional");
put("optional.int", "9");
put("info.name", "server");
put("info.login", "login");
put("info.password", "password");
}
};

Expand All @@ -257,6 +260,13 @@ void optionals() {
assertEquals("optional", optionals.optional().get());
assertTrue(optionals.optionalInt().isPresent());
assertEquals(9, optionals.optionalInt().getAsInt());

assertFalse(optionals.info().isEmpty());
assertEquals("server", optionals.info().get("info").name());
assertTrue(optionals.info().get("info").login().isPresent());
assertEquals("login", optionals.info().get("info").login().get());
assertTrue(optionals.info().get("info").password().isPresent());
assertEquals("password", optionals.info().get("info").password().get());
}

@Test
Expand Down Expand Up @@ -607,6 +617,17 @@ public interface Optionals {

@WithName("optional.int")
OptionalInt optionalInt();

@WithParentName
Map<String, Info> info();

interface Info {
String name();

Optional<String> login();

Optional<String> password();
}
}

public interface CollectionTypes {
Expand Down

0 comments on commit 8e0aa94

Please sign in to comment.