From 7f19125a7b5b683ccb5d5056675fcc881f68dbe9 Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Tue, 3 May 2022 22:47:31 +0200 Subject: [PATCH] CustomCollections is now less invasive to ConversionService. Removed the removal of the general collection-to-object converter as apparently some downstream Spring Data modules rely on it. This theoretically allows conversions of collections into maps but we now simply don't assume that not to work anymore. Issue #2619. --- .../java/org/springframework/data/util/CustomCollections.java | 4 +--- .../springframework/data/util/CustomCollectionsUnitTests.java | 4 ---- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/main/java/org/springframework/data/util/CustomCollections.java b/src/main/java/org/springframework/data/util/CustomCollections.java index db32f944e..2e7c9a64b 100644 --- a/src/main/java/org/springframework/data/util/CustomCollections.java +++ b/src/main/java/org/springframework/data/util/CustomCollections.java @@ -184,9 +184,6 @@ public class CustomCollections { Assert.notNull(registry, "ConverterRegistry must not be null!"); - // Remove general collection to anything conversion as that would also convert collections to maps - registry.removeConvertible(Collection.class, Object.class); - REGISTRARS.forEach(it -> it.registerConvertersIn(registry)); } @@ -352,6 +349,7 @@ public class CustomCollections { * @see org.springframework.data.util.CustomCollectionRegistrar#toJavaNativeCollection() */ @Override + @SuppressWarnings("null") public Function toJavaNativeCollection() { return source -> source instanceof io.vavr.collection.Traversable diff --git a/src/test/java/org/springframework/data/util/CustomCollectionsUnitTests.java b/src/test/java/org/springframework/data/util/CustomCollectionsUnitTests.java index 60d411487..f6139a325 100644 --- a/src/test/java/org/springframework/data/util/CustomCollectionsUnitTests.java +++ b/src/test/java/org/springframework/data/util/CustomCollectionsUnitTests.java @@ -95,7 +95,6 @@ class CustomCollectionsUnitTests { assertThat(conversionService.canConvert(List.class, io.vavr.collection.Traversable.class)).isTrue(); assertThat(conversionService.canConvert(List.class, io.vavr.collection.List.class)).isTrue(); assertThat(conversionService.canConvert(List.class, io.vavr.collection.Set.class)).isTrue(); - assertThat(conversionService.canConvert(List.class, io.vavr.collection.Map.class)).isFalse(); List integers = Arrays.asList(1, 2, 3); @@ -111,7 +110,6 @@ class CustomCollectionsUnitTests { assertThat(conversionService.canConvert(Set.class, io.vavr.collection.Traversable.class)).isTrue(); assertThat(conversionService.canConvert(Set.class, io.vavr.collection.Set.class)).isTrue(); assertThat(conversionService.canConvert(Set.class, io.vavr.collection.List.class)).isTrue(); - assertThat(conversionService.canConvert(Set.class, io.vavr.collection.Map.class)).isFalse(); Set integers = Collections.singleton(1); @@ -143,7 +141,6 @@ class CustomCollectionsUnitTests { assertThat(conversionService.canConvert(List.class, ImmutableList.class)).isTrue(); assertThat(conversionService.canConvert(List.class, ImmutableSet.class)).isTrue(); assertThat(conversionService.canConvert(List.class, ImmutableBag.class)).isTrue(); - assertThat(conversionService.canConvert(List.class, ImmutableMap.class)).isFalse(); List integers = Arrays.asList(1, 2, 3); @@ -162,7 +159,6 @@ class CustomCollectionsUnitTests { assertThat(conversionService.canConvert(Set.class, ImmutableSet.class)).isTrue(); assertThat(conversionService.canConvert(Set.class, ImmutableBag.class)).isTrue(); assertThat(conversionService.canConvert(Set.class, ImmutableList.class)).isTrue(); - assertThat(conversionService.canConvert(Set.class, ImmutableMap.class)).isFalse(); Set integers = Collections.singleton(1);