Skip to content

Commit

Permalink
Adjust logic to avoid changing binary form
Browse files Browse the repository at this point in the history
  • Loading branch information
jodastephen committed Dec 30, 2024
1 parent 4d9df1c commit bfb9727
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
9 changes: 7 additions & 2 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
Potentially incompatible change:
The standard and referencing binary formats now support null as a map key.
</action>
<action dev="jodastephen" type="add" issue="230">
Potentially incompatible change:
The referencing binary format no longer deduplicates collections.
The old format can still be parsed successfully.
</action>
<action dev="jodastephen" type="add" issue="446">
Potentially incompatible change:
The standard binary and simple JSON formats now handle `Iterable` as a collection type.
Expand All @@ -44,15 +49,15 @@
Instead of a Joda-Convert formatted string, the array is output as a list of primitives.
This also applies to multi-dimensional arrays.
This is a much more natural JSON format.
The old format cam still be parsed successfully.
The old format can still be parsed successfully.
</action>
<action dev="jodastephen" type="update">
Incompatible change:
The JSON serialization formats have changed requiring fewer @meta and @type annotations.
For example, where the type of the collection is Object,
previously a String value was explicitly typed as a String, now the type is implicit.
This is a much more natural JSON format.
The old format cam still be parsed successfully.
The old format can still be parsed successfully.
</action>
<action dev="jodastephen" type="update" issue="192">
Incompatible change:
Expand Down
30 changes: 11 additions & 19 deletions src/main/java/org/joda/beans/ser/bin/BeanReferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,18 @@ private void findReferencesBean(
return;
}

if (base instanceof Bean) {
// has this object been seen before, if so no need to check it again
var result = objects.compute(base, BeanReferences::incrementOrOne);
if (result > 1) {
return;
// has this object been seen before, if so no need to check it again
if (objects.compute(base, BeanReferences::incrementOrOne) > 1) {
// shouldn't try and reuse references to collections
if (!(base instanceof Bean) && parentIterator != null) {
var childIterator = settings.getIteratorFactory().createChild(base, parentIterator);
if (childIterator != null) {
findReferencesIterable(childIterator, objects);
}
}

return;
}
if (base instanceof Bean bean) {
addClassInfo(base, declaredClass);
if (settings.getConverter().isConvertible(bean.getClass())) {
return;
Expand All @@ -165,25 +170,12 @@ private void findReferencesBean(
} else if (parentIterator != null) {
var childIterator = settings.getIteratorFactory().createChild(base, parentIterator);
if (childIterator != null) {
if (childIterator.metaTypeRequired()) {
objects.compute(childIterator.metaTypeName(), BeanReferences::incrementOrOne);
}
// shouldn't try and reuse references to collections
findReferencesIterable(childIterator, objects);
} else {
// has this object been seen before, if so no need to check it again
int result = objects.compute(base, BeanReferences::incrementOrOne);
if (result > 1) {
return;
}
addClassInfo(base, declaredClass);
}
} else {
// has this object been seen before, if so no need to check it again
int result = objects.compute(base, BeanReferences::incrementOrOne);
if (result > 1) {
return;
}
addClassInfo(base, declaredClass);
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/test/java/org/joda/beans/ser/SerTestHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,13 @@ public static ImmGenericCollections<JodaConvertInterface> testGenericInterfaces(

public static ImmGenericCollections<Object> testGenericInterfacesCollections() {
return ImmGenericCollections.builder()
.map(ImmutableMap.of(
"First", Arrays.asList("A", "B"),
"First1", ImmutableList.of("A", "B"),
"Third1", new TreeSet<>(ImmutableList.of("A", "B")),
"Third", new HashSet<>(Arrays.asList("A", "B")),
"Second", testCollections()))
.build();
.map(ImmutableMap.of(
"First", Arrays.asList("A", "B"),
"First1", ImmutableList.of("A", "B"),
"Third1", new TreeSet<>(ImmutableList.of("A", "B")),
"Third", new HashSet<>(Arrays.asList("A", "B")),
"Second", testCollections(true)))
.build();
}

public static ImmKeyList testIntermediateInterfaces() {
Expand Down

0 comments on commit bfb9727

Please sign in to comment.