From 23ad2f0b3f0a19e843043df5345693bddc344862 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 cbdc51d43..7fd273e3a 100644 --- a/src/main/java/org/springframework/data/util/CustomCollections.java +++ b/src/main/java/org/springframework/data/util/CustomCollections.java @@ -182,9 +182,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)); } @@ -350,6 +347,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 fbe4b157d..6a617fa17 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(); var integers = Arrays.asList(1, 2, 3); @@ -110,7 +109,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(); var integers = Collections.singleton(1); @@ -141,7 +139,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); @@ -160,7 +157,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(); var integers = Collections.singleton(1);