Skip to content

Commit 5fee961

Browse files
committed
Fix: Convert PersistentBag to ArrayList in CollectionConverterCompatibility
1 parent e769c4b commit 5fee961

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

api-2.0/src/main/java/org/openmrs/module/metadatasharing/serializer/converter/CollectionConverterCompatibility2_0.java

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,25 @@ public boolean canConvert(Class type) {
4545
}
4646

4747
@Override
48-
public void marshal(Object source, HierarchicalStreamWriter writer,
49-
MarshallingContext context, ConverterLookup converterLookup) {
50-
51-
if (source instanceof PersistentList) {
52-
source = new ArrayList((Collection) source);
53-
} else if (source instanceof PersistentMap) {
54-
source = new HashMap((Map) source);
55-
} else if (source instanceof PersistentSortedMap) {
56-
source = new TreeMap((SortedMap) source);
57-
} else if (source instanceof PersistentSortedSet) {
58-
source = new TreeSet((SortedSet) source);
59-
} else if (source instanceof PersistentSet) {
60-
source = new HashSet((Set) source);
61-
}
62-
63-
// delegate the collection to the appropriate converter
64-
converterLookup.lookupConverterForType(source.getClass()).marshal(source, writer, context);
65-
}
48+
public void marshal(Object source, HierarchicalStreamWriter writer,
49+
MarshallingContext context, ConverterLookup converterLookup) {
50+
51+
if (source instanceof PersistentBag) {
52+
source = new ArrayList<>((Collection<?>) source);
53+
} else if (source instanceof PersistentList) {
54+
source = new ArrayList<>((Collection<?>) source);
55+
} else if (source instanceof PersistentMap) {
56+
source = new HashMap<>((Map<?, ?>) source);
57+
} else if (source instanceof PersistentSortedMap) {
58+
source = new TreeMap<>((SortedMap<?, ?>) source);
59+
} else if (source instanceof PersistentSortedSet) {
60+
source = new TreeSet<>((SortedSet<?>) source);
61+
} else if (source instanceof PersistentSet) {
62+
source = new HashSet<>((Set<?>) source);
63+
}
64+
65+
// Delegate to appropriate converter
66+
converterLookup.lookupConverterForType(source.getClass()).marshal(source, writer, context);
67+
}
68+
6669
}

0 commit comments

Comments
 (0)