Skip to content

Conversation

@jamezp
Copy link
Member

@jamezp jamezp commented Sep 24, 2025

…eady been resolved.

resolves #682

Copy link
Member

@KyleAure KyleAure left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix looks good.
I think all we are missing from the tests are appropriate de-serialization testing for the same scenario. This looks like common practice in this test class so I added those suggestions below.

Comment on lines +527 to +530
// Use a new instance of Jsonb to avoid any caching
try (var jsonb = JsonbBuilder.create()) {
assertEquals(expectedJson, jsonb.toJson(container));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Use a new instance of Jsonb to avoid any caching
try (var jsonb = JsonbBuilder.create()) {
assertEquals(expectedJson, jsonb.toJson(container));
}
// Use a new instance of Jsonb to avoid any caching
try (var jsonb = JsonbBuilder.create()) {
assertEquals(expectedJson, jsonb.toJson(container));
TreeContainer<TreeElement> result = jsonb.fromJson(expectedJson, new TestTypeToken<TreeContainer<TreeElement>>() {}.getType());
assertIterableEquals(container.getTree().getChildren(), result.getTree().getChildren());
}

Requires addition of:

import static org.junit.jupiter.api.Assertions.assertIterableEquals;

Comment on lines +542 to +545
// Use a new instance of Jsonb to avoid any caching
try (var jsonb = JsonbBuilder.create()) {
assertEquals(expectedJson, jsonb.toJson(container));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Use a new instance of Jsonb to avoid any caching
try (var jsonb = JsonbBuilder.create()) {
assertEquals(expectedJson, jsonb.toJson(container));
}
// Use a new instance of Jsonb to avoid any caching
try (var jsonb = JsonbBuilder.create()) {
assertEquals(expectedJson, jsonb.toJson(container));
ListContainer<TreeElement> result = jsonb.fromJson(expectedJson, new TestTypeToken<ListContainer<TreeElement>>() {}.getType());
assertIterableEquals(container.getList(), result.getList());
}

Requires addition of:

import static org.junit.jupiter.api.Assertions.assertIterableEquals;

public class TreeElement implements TreeTypeContainer<TreeElement> {
public class TreeElement extends TreeTypeContainer<TreeElement> {

private final String name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private final String name;
private String name;
public TreeElement() {
}

suggestion: allow for deserialization

public void setChildren(final List<TreeElement> children) {
this.children = children;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
public void setName(final String name) {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
TreeElement that = (TreeElement) o;
return name != null ? name.equals(that.name) : that.name == null;
}
}

suggestion: allow for deserialization and assertions.

public void setChildren(final List<T> children) {
this.children = children;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
TreeTypeContainer<?> that = (TreeTypeContainer<?>) o;
if (children == null) {
return that.children == null;
}
return children.containsAll(that.children) && that.children.containsAll(children);
}
}

Suggestion: allow for assertions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Serialization may throw an exception when a generic bound type is discovered, but not of type Class

2 participants