26
26
import java .util .concurrent .CompletableFuture ;
27
27
import java .util .concurrent .ConcurrentHashMap ;
28
28
import java .util .concurrent .Future ;
29
+ import java .util .function .Function ;
29
30
import java .util .stream .Stream ;
30
31
31
32
import org .springframework .core .convert .ConversionService ;
38
39
import org .springframework .data .domain .Page ;
39
40
import org .springframework .data .domain .Slice ;
40
41
import org .springframework .data .geo .GeoResults ;
42
+ import org .springframework .data .util .CustomCollections ;
41
43
import org .springframework .data .util .NullableWrapper ;
42
44
import org .springframework .data .util .NullableWrapperConverters ;
43
45
import org .springframework .data .util .StreamUtils ;
44
46
import org .springframework .data .util .Streamable ;
45
47
import org .springframework .data .util .TypeInformation ;
46
- import org .springframework .data . util . VavrCollectionConverters ;
48
+ import org .springframework .lang . NonNull ;
47
49
import org .springframework .lang .Nullable ;
48
50
import org .springframework .scheduling .annotation .AsyncResult ;
49
51
import org .springframework .util .Assert ;
@@ -80,7 +82,7 @@ public abstract class QueryExecutionConverters {
80
82
81
83
private static final Set <WrapperType > WRAPPER_TYPES = new HashSet <>();
82
84
private static final Set <WrapperType > UNWRAPPER_TYPES = new HashSet <WrapperType >();
83
- private static final Set <Converter <Object , Object >> UNWRAPPERS = new HashSet <>();
85
+ private static final Set <Function <Object , Object >> UNWRAPPERS = new HashSet <>();
84
86
private static final Set <Class <?>> ALLOWED_PAGEABLE_TYPES = new HashSet <>();
85
87
private static final Map <Class <?>, ExecutionAdapter > EXECUTION_ADAPTER = new HashMap <>();
86
88
private static final Map <Class <?>, Boolean > supportsCache = new ConcurrentReferenceHashMap <>();
@@ -98,16 +100,19 @@ public abstract class QueryExecutionConverters {
98
100
99
101
WRAPPER_TYPES .add (NullableWrapperToCompletableFutureConverter .getWrapperType ());
100
102
101
- if (VAVR_PRESENT ) {
103
+ UNWRAPPERS .addAll (CustomCollections .getUnwrappers ());
104
+
105
+ CustomCollections .getCustomTypes ().stream ()
106
+ .map (WrapperType ::multiValue )
107
+ .forEach (WRAPPER_TYPES ::add );
102
108
103
- WRAPPER_TYPES .add (VavrTraversableUnwrapper .INSTANCE .getWrapperType ());
104
- UNWRAPPERS .add (VavrTraversableUnwrapper .INSTANCE );
109
+ CustomCollections .getPaginationReturnTypes ().forEach (ALLOWED_PAGEABLE_TYPES ::add );
110
+
111
+ if (VAVR_PRESENT ) {
105
112
106
113
// Try support
107
114
WRAPPER_TYPES .add (WrapperType .singleValue (io .vavr .control .Try .class ));
108
115
EXECUTION_ADAPTER .put (io .vavr .control .Try .class , it -> io .vavr .control .Try .of (it ::get ));
109
-
110
- ALLOWED_PAGEABLE_TYPES .add (io .vavr .collection .Seq .class );
111
116
}
112
117
}
113
118
@@ -195,10 +200,7 @@ public static void registerConvertersIn(ConfigurableConversionService conversion
195
200
conversionService .removeConvertible (Collection .class , Object .class );
196
201
197
202
NullableWrapperConverters .registerConvertersIn (conversionService );
198
-
199
- if (VAVR_PRESENT ) {
200
- conversionService .addConverter (VavrCollectionConverters .FromJavaConverter .INSTANCE );
201
- }
203
+ CustomCollections .registerConvertersIn (conversionService );
202
204
203
205
conversionService .addConverter (new NullableWrapperToCompletableFutureConverter ());
204
206
conversionService .addConverter (new NullableWrapperToFutureConverter ());
@@ -220,9 +222,9 @@ public static Object unwrap(@Nullable Object source) {
220
222
return source ;
221
223
}
222
224
223
- for (Converter <Object , Object > converter : UNWRAPPERS ) {
225
+ for (Function <Object , Object > converter : UNWRAPPERS ) {
224
226
225
- Object result = converter .convert (source );
227
+ Object result = converter .apply (source );
226
228
227
229
if (result != source ) {
228
230
return result ;
@@ -382,36 +384,6 @@ static WrapperType getWrapperType() {
382
384
}
383
385
}
384
386
385
- /**
386
- * Converter to unwrap Vavr {@link io.vavr.collection.Traversable} instances.
387
- *
388
- * @author Oliver Gierke
389
- * @since 2.0
390
- */
391
- private enum VavrTraversableUnwrapper implements Converter <Object , Object > {
392
-
393
- INSTANCE ;
394
-
395
- private static final TypeDescriptor OBJECT_DESCRIPTOR = TypeDescriptor .valueOf (Object .class );
396
-
397
- @ Nullable
398
- @ Override
399
- @ SuppressWarnings ("null" )
400
- public Object convert (Object source ) {
401
-
402
- if (source instanceof io .vavr .collection .Traversable ) {
403
- return VavrCollectionConverters .ToJavaConverter .INSTANCE //
404
- .convert (source , TypeDescriptor .forObject (source ), OBJECT_DESCRIPTOR );
405
- }
406
-
407
- return source ;
408
- }
409
-
410
- public WrapperType getWrapperType () {
411
- return WrapperType .multiValue (io .vavr .collection .Traversable .class );
412
- }
413
- }
414
-
415
387
private static class IterableToStreamableConverter implements ConditionalGenericConverter {
416
388
417
389
private static final TypeDescriptor STREAMABLE = TypeDescriptor .valueOf (Streamable .class );
@@ -477,7 +449,7 @@ public Cardinality getCardinality() {
477
449
}
478
450
479
451
@ Override
480
- public boolean equals (Object o ) {
452
+ public boolean equals (@ Nullable Object o ) {
481
453
482
454
if (this == o ) {
483
455
return true ;
0 commit comments