@@ -409,10 +409,15 @@ public void write(@Nullable Object source, RedisData sink) {
409
409
if (collection instanceof List ) {
410
410
collectionTargetType = List .class ;
411
411
} else if (collection instanceof Set ) {
412
- collectionTargetType = collection instanceof EnumSet ? EnumSet .class : Set .class ;
412
+ if (collection instanceof EnumSet <?>) {
413
+ collectionTargetType = EnumSet .class ;
414
+ } else {
415
+ collectionTargetType = Set .class ;
416
+ }
413
417
}
418
+
414
419
typeMapper .writeType (collectionTargetType , sink .getBucket ().getPath ());
415
- writeCollection (sink .getKeyspace (), "" , collection , TypeInformation .of ( Object . class ) , sink );
420
+ writeCollection (sink .getKeyspace (), "" , collection , TypeInformation .OBJECT , sink );
416
421
return ;
417
422
}
418
423
@@ -829,7 +834,13 @@ private void writeToBucket(String path, @Nullable Object value, RedisData sink,
829
834
830
835
boolean isArray = collectionType .isArray ();
831
836
Class <?> collectionTypeToUse = isArray ? ArrayList .class : collectionType ;
832
- Collection <Object > target = CollectionFactory .createCollection (collectionTypeToUse , valueType , keys .size ());
837
+ Class <?> valueTypeToUse = valueType ;
838
+
839
+ if (collectionTypeToUse == EnumSet .class ) {
840
+ valueTypeToUse = findFirstElementType (bucket , keys , valueType );
841
+ }
842
+
843
+ Collection <Object > target = CollectionFactory .createCollection (collectionTypeToUse , valueTypeToUse , keys .size ());
833
844
834
845
for (String key : keys ) {
835
846
@@ -977,6 +988,17 @@ private void writeMap(@Nullable String keyspace, String path, Class<?> mapValueT
977
988
return conversionService .convert (toBytes (mapKey ), targetType );
978
989
}
979
990
991
+ private Class <?> findFirstElementType (Bucket bucket , List <String > keys , Class <?> fallbackType ) {
992
+
993
+ Optional <String > firstElement = keys .stream ().filter (typeMapper ::isTypeKey )
994
+ .map (it -> it .substring (0 , it .indexOf (']' ) + 1 )).findFirst ();
995
+ if (firstElement .isEmpty ()) {
996
+ return fallbackType ;
997
+ }
998
+
999
+ return getTypeHint (firstElement .get (), bucket , fallbackType );
1000
+ }
1001
+
980
1002
private Class <?> getTypeHint (String path , Bucket bucket , Class <?> fallback ) {
981
1003
982
1004
TypeInformation <?> typeInformation = typeMapper .readType (bucket .getPropertyPath (path ),
0 commit comments