Skip to content

Commit

Permalink
Fix set a recursive object (#1079)
Browse files Browse the repository at this point in the history
  • Loading branch information
seongahjo authored Nov 11, 2024
1 parent b16f316 commit f610f6d
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/content/v1.1.x-kor/release-notes/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ menu:
docs:
weight: 100
---
sectionStart
## v.1.1.1
Fix set a recursive object

sectionEnd

sectionStart
## v.1.0.28
Add support for `hashCode`, `equals`, `toString` in anonymous object
Expand Down
6 changes: 6 additions & 0 deletions docs/content/v1.1.x/release-notes/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ menu:
docs:
weight: 100
---
sectionStart
## v.1.1.1
Fix set a recursive object

sectionEnd

sectionStart
## v.1.0.28
Add support for `hashCode`, `equals`, `toString` in anonymous object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,18 @@ void setNestedSelfRecursiveObjectList() {
then(actual).isEqualTo(expected);
}

@RepeatedTest(TEST_COUNT)
void setSelfRecursiveObject() {
SelfRecursiveObject actual = SUT.giveMeOne(SelfRecursiveObject.class);

SelfRecursiveObject expected = SUT.giveMeBuilder(SelfRecursiveObject.class)
.set("selfRecursiveObject", actual)
.sample()
.getSelfRecursiveObject();

then(actual).isEqualTo(expected);
}

@RepeatedTest(TEST_COUNT)
void thenApplyAndSizeMap() {
Map<String, String> actual = SUT.giveMeBuilder(new TypeReference<Map<String, Map<String, String>>>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private void setValue(ObjectNode objectNode, @Nullable Object value) {
objectNode.setResolvedTypeDefinition(typeDefinition);
}

objectNode.expand(typeDefinition);
objectNode.forceExpand(typeDefinition);
for (ObjectNode child : objectNode.getChildren()) {
if (!typeDefinition.equals(child.getParent().getResolvedTypeDefinition())) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,28 @@ public void forceExpand() {
this.expandedTypeDefinition = resolvedTypeDefinition;
}

public void forceExpand(TypeDefinition typeDefinition) {
List<ObjectNode> newChildren;
if (this.getTreeProperty().isContainer()) {
newChildren = expandContainerNode(
typeDefinition,
this.traverseContext.withoutRecursiveTreeProperties()
)
.collect(Collectors.toList());
} else {
newChildren = this.generateChildrenNodes(
typeDefinition.getResolvedProperty(),
typeDefinition.getPropertyGenerator()
.generateChildProperties(typeDefinition.getResolvedProperty()),
this.nullInject,
this.traverseContext.withoutRecursiveTreeProperties()
);
}

this.setChildren(newChildren);
this.expandedTypeDefinition = resolvedTypeDefinition;
}

private Stream<ObjectNode> expandContainerNode(TypeDefinition typeDefinition, TraverseContext traverseContext) {
ContainerInfoManipulator appliedContainerInfoManipulator =
this.getAppliedContainerInfoManipulator();
Expand Down

0 comments on commit f610f6d

Please sign in to comment.