From 796ea2a7bd883f87c708d7c5adec8e06c95f1057 Mon Sep 17 00:00:00 2001 From: Chathuni Sooriyaarachchi Date: Wed, 2 Apr 2025 15:18:26 +0530 Subject: [PATCH] Fix: Generalized PersistentCollection conversion in CollectionConverterCompatibility --- .../CollectionConverterCompatibility2_0.java | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/api-2.0/src/main/java/org/openmrs/module/metadatasharing/serializer/converter/CollectionConverterCompatibility2_0.java b/api-2.0/src/main/java/org/openmrs/module/metadatasharing/serializer/converter/CollectionConverterCompatibility2_0.java index a3eb53d..8d59a0c 100644 --- a/api-2.0/src/main/java/org/openmrs/module/metadatasharing/serializer/converter/CollectionConverterCompatibility2_0.java +++ b/api-2.0/src/main/java/org/openmrs/module/metadatasharing/serializer/converter/CollectionConverterCompatibility2_0.java @@ -46,21 +46,14 @@ public boolean canConvert(Class type) { @Override public void marshal(Object source, HierarchicalStreamWriter writer, - MarshallingContext context, ConverterLookup converterLookup) { - - if (source instanceof PersistentList) { - source = new ArrayList((Collection) source); - } else if (source instanceof PersistentMap) { - source = new HashMap((Map) source); - } else if (source instanceof PersistentSortedMap) { - source = new TreeMap((SortedMap) source); - } else if (source instanceof PersistentSortedSet) { - source = new TreeSet((SortedSet) source); - } else if (source instanceof PersistentSet) { - source = new HashSet((Set) source); + MarshallingContext context, ConverterLookup converterLookup) { + + if (source instanceof PersistentCollection) { + source = new ArrayList<>((Collection) source); } - - // delegate the collection to the appropriate converter + + // Delegate to the appropriate converter converterLookup.lookupConverterForType(source.getClass()).marshal(source, writer, context); } + }