LouisLou2 opened a new issue, #2105: URL: https://github.com/apache/fury/issues/2105
### Search before asking - [x] I had searched in the [issues](https://github.com/apache/fury/issues) and found no similar issues. ### Version 0.10.0 ### Component(s) Java ### Minimal reproduce step ```java package org.apache.fury; import org.apache.fury.config.Language; import java.util.HashSet; import java.util.Set; public class Main { public static class SomeClass { Set<String> set = new HashSet<>(); } public static void main(String[] args) { Fury fury = Fury.builder() .withLanguage(Language.XLANG) .withRefTracking(true) .ignoreBasicTypesRef(true) .ignoreTimeRef(true) .ignoreStringRef(false) .build(); fury.register(SomeClass.class, "MySomeClass"); SomeClass someClass = new SomeClass(); byte[] bytes = fury.serialize(someClass); SomeClass obj = (SomeClass)fury.deserialize(bytes); System.out.println(obj.set.getClass()); } } ``` ### What did you expect to see? I expected the deserialized object to maintain the same collection type as the original object - a HashSet in this case. Since the field is declared as a Set<String>, it should be deserialized as a Set implementation like HashSet, preserving the collection's semantics (uniqueness of elements, hash-based operations, etc.). ### What did you see instead? The deserialized object contains an ArrayList instead of a HashSet: ```bash class java.util.ArrayList ``` The Set is converted to an ArrayList during deserialization, which breaks the expected behavior of the Set interface (no duplicate elements, different performance characteristics for operations like contains()). ### Anything Else? I've traced the issue to the StructSerializer::getGenericType method which contains the following logic: ```java if (resolver.isMap(cls)) { t.setSerializer( ReflectionUtils.isAbstract(cls) ? new MapSerializer(fury, HashMap.class) : resolver.getSerializer(cls)); } else if (resolver.isCollection(cls)) { t.setSerializer( ReflectionUtils.isAbstract(cls) ? new CollectionSerializer(fury, ArrayList.class) : resolver.getSerializer(cls)); } else if (cls.isArray()) { t.setSerializer(new ArraySerializers.ObjectArraySerializer(fury, cls)); } ``` When the serializer detects a field is a Collection and its class is abstract (which includes interfaces like Set), it defaults to using ArrayList as the implementation rather than preserving the original collection type. While this approach makes the code work (the elements are preserved), it changes the semantics of the collection. This can lead to unexpected behavior for code that relies on specific collection implementations or interfaces. ### Are you willing to submit a PR? - [x] I'm willing to submit a PR! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
