DATACMNS-1336 - Avoid warning logs for JodaTime and ThreeTenBP converter registrations.
Removed the explicit registration for JodaTime and ThreeTenBP to JSR-310 converters (originally introduced to support the unifying lookup of the last modified date in the auditing subsystem) as reading converters. This avoids the warning reporting that the source types (JodaTime and ThreeTenBP LocalDateTime) not being store-native types (which usually indicates a superfluous converter registration). Updated the test cases to make sure these warnings aren't trigger due to test setups causing the same issue.
This commit is contained in:
@@ -75,7 +75,6 @@ public abstract class JodaTimeConverters {
|
||||
return converters;
|
||||
}
|
||||
|
||||
@ReadingConverter
|
||||
public enum LocalDateTimeToJsr310Converter implements Converter<LocalDateTime, java.time.LocalDateTime> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@@ -53,6 +53,14 @@ public abstract class ThreeTenBackPortConverters {
|
||||
|
||||
private static final boolean THREE_TEN_BACK_PORT_IS_PRESENT = ClassUtils.isPresent("org.threeten.bp.LocalDateTime",
|
||||
ThreeTenBackPortConverters.class.getClassLoader());
|
||||
private static final Collection<Class<?>> SUPPORTED_TYPES;
|
||||
|
||||
static {
|
||||
|
||||
SUPPORTED_TYPES = THREE_TEN_BACK_PORT_IS_PRESENT //
|
||||
? Arrays.asList(LocalDateTime.class, LocalDate.class, LocalTime.class, Instant.class, java.time.Instant.class)
|
||||
: Collections.emptySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the converters to be registered. Will only return converters in case we're running on Java 8.
|
||||
@@ -84,16 +92,9 @@ public abstract class ThreeTenBackPortConverters {
|
||||
}
|
||||
|
||||
public static boolean supports(Class<?> type) {
|
||||
|
||||
if (!THREE_TEN_BACK_PORT_IS_PRESENT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Arrays.<Class<?>> asList(LocalDateTime.class, LocalDate.class, LocalTime.class, Instant.class, java.time.Instant.class)
|
||||
.contains(type);
|
||||
return SUPPORTED_TYPES.contains(type);
|
||||
}
|
||||
|
||||
@ReadingConverter
|
||||
public static enum LocalDateTimeToJsr310LocalDateTimeConverter
|
||||
implements Converter<LocalDateTime, java.time.LocalDateTime> {
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.core.convert.support.GenericConversionService;
|
||||
import org.springframework.data.convert.ConverterBuilder.ConverterAware;
|
||||
import org.springframework.data.convert.CustomConversions.StoreConversions;
|
||||
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||
import org.threeten.bp.LocalDateTime;
|
||||
|
||||
/**
|
||||
@@ -166,7 +167,9 @@ public class CustomConversionsUnitTests {
|
||||
@Test // DATAMONGO-1302, DATACMNS-1035
|
||||
public void registersConverterFactoryCorrectly() {
|
||||
|
||||
CustomConversions customConversions = new CustomConversions(StoreConversions.NONE,
|
||||
StoreConversions conversions = StoreConversions.of(new SimpleTypeHolder(Collections.singleton(Format.class), true));
|
||||
|
||||
CustomConversions customConversions = new CustomConversions(conversions,
|
||||
Collections.singletonList(new FormatConverterFactory()));
|
||||
|
||||
assertThat(customConversions.getCustomWriteTarget(String.class, SimpleDateFormat.class)).isPresent();
|
||||
@@ -175,19 +178,20 @@ public class CustomConversionsUnitTests {
|
||||
@Test // DATACMNS-1034
|
||||
public void registersConverterFromConverterAware() {
|
||||
|
||||
ConverterAware converters = ConverterBuilder.reading(Left.class, Right.class, left -> new Right())
|
||||
.andWriting(right -> new Left());
|
||||
ConverterAware converters = ConverterBuilder //
|
||||
.reading(Locale.class, CustomType.class, left -> new CustomType()) //
|
||||
.andWriting(right -> Locale.GERMAN);
|
||||
|
||||
CustomConversions conversions = new CustomConversions(StoreConversions.NONE, Collections.singletonList(converters));
|
||||
|
||||
assertThat(conversions.hasCustomWriteTarget(Right.class)).isTrue();
|
||||
assertThat(conversions.hasCustomReadTarget(Left.class, Right.class)).isTrue();
|
||||
assertThat(conversions.hasCustomWriteTarget(CustomType.class)).isTrue();
|
||||
assertThat(conversions.hasCustomReadTarget(Locale.class, CustomType.class)).isTrue();
|
||||
|
||||
ConfigurableConversionService conversionService = new GenericConversionService();
|
||||
conversions.registerConvertersIn(conversionService);
|
||||
|
||||
assertThat(conversionService.canConvert(Left.class, Right.class)).isTrue();
|
||||
assertThat(conversionService.canConvert(Right.class, Left.class)).isTrue();
|
||||
assertThat(conversionService.canConvert(CustomType.class, Locale.class)).isTrue();
|
||||
assertThat(conversionService.canConvert(Locale.class, CustomType.class)).isTrue();
|
||||
}
|
||||
|
||||
private static Class<?> createProxyTypeFor(Class<?> type) {
|
||||
@@ -307,7 +311,5 @@ public class CustomConversionsUnitTests {
|
||||
}
|
||||
}
|
||||
|
||||
static class Left {}
|
||||
|
||||
static class Right {}
|
||||
static class CustomType {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user