Complete Vavr collection detection on TypeInformation and CustomConversions.

Moved Vavr collection converters into a type in the utility package. Register the converters via CustomConversions.registerConvertersIn(…) to make sure that all the Spring Data object mapping converters automatically benefit from a ConversionService that is capable of translating between Java-native collections and Vavr ones.

Issue #2511.
This commit is contained in:
Oliver Drotbohm
2021-12-11 11:22:33 +01:00
parent 5b568953e9
commit f933b4562e
5 changed files with 106 additions and 59 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011-2021 the original author or authors.
* Copyright 2011-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@ import static org.mockito.Mockito.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.function.Predicate;
@@ -30,7 +31,6 @@ import org.jmolecules.ddd.types.Association;
import org.jmolecules.ddd.types.Identifier;
import org.joda.time.DateTime;
import org.junit.jupiter.api.Test;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.converter.ConverterFactory;
@@ -46,7 +46,6 @@ import org.springframework.data.convert.Jsr310Converters.LocalDateTimeToDateConv
import org.springframework.data.convert.ThreeTenBackPortConverters.LocalDateTimeToJavaTimeInstantConverter;
import org.springframework.data.geo.Point;
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.threeten.bp.LocalDateTime;
/**
@@ -292,6 +291,18 @@ class CustomConversionsUnitTests {
assertThat(conversions.hasCustomReadTarget(String.class, Identifier.class)).isTrue();
}
@Test // GH-2511
void registersVavrConverters() {
ConfigurableConversionService conversionService = new DefaultConversionService();
new CustomConversions(StoreConversions.NONE, Collections.emptyList())
.registerConvertersIn(conversionService);
assertThat(conversionService.canConvert(io.vavr.collection.List.class, List.class)).isTrue();
assertThat(conversionService.canConvert(List.class, io.vavr.collection.List.class)).isTrue();
}
private static Class<?> createProxyTypeFor(Class<?> type) {
ProxyFactory factory = new ProxyFactory();