DATACMNS-1109 - Reinstantiate support for all date/time APIs in auditing.
Re-enabled test cases for handling of different date/time APIs in auditing. Tweaked the lookup of the last modified value to try to convert to LocalDateTime as well in case it's a subtype of the type requested. In combination with two newly introduced converters for local date type times in JodaTime and ThreeTenBP, this allows us to still convert legacy JodaTime and ThreeTenBP types to be used as well.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.convert;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -35,7 +36,6 @@ import org.springframework.util.ClassUtils;
|
||||
* @author Christoph Strobl
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public abstract class JodaTimeConverters {
|
||||
|
||||
private static final boolean JODA_TIME_IS_PRESENT = ClassUtils.isPresent("org.joda.time.LocalDate", null);
|
||||
@@ -63,9 +63,21 @@ public abstract class JodaTimeConverters {
|
||||
converters.add(LocalDateTimeToJodaLocalDateTime.INSTANCE);
|
||||
converters.add(LocalDateTimeToJodaDateTime.INSTANCE);
|
||||
|
||||
converters.add(LocalDateTimeToJsr310Converter.INSTANCE);
|
||||
|
||||
return converters;
|
||||
}
|
||||
|
||||
public enum LocalDateTimeToJsr310Converter implements Converter<LocalDateTime, java.time.LocalDateTime> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public java.time.LocalDateTime convert(LocalDateTime source) {
|
||||
return source == null ? null : java.time.LocalDateTime.ofInstant(source.toDate().toInstant(), ZoneId.of("UTC"));
|
||||
}
|
||||
}
|
||||
|
||||
public enum LocalDateToDateConverter implements Converter<LocalDate, Date> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@@ -71,6 +71,7 @@ public abstract class ThreeTenBackPortConverters {
|
||||
converters.add(InstantToDateConverter.INSTANCE);
|
||||
converters.add(ZoneIdToStringConverter.INSTANCE);
|
||||
converters.add(StringToZoneIdConverter.INSTANCE);
|
||||
converters.add(LocalDateTimeToJsr310LocalDateTimeConverter.INSTANCE);
|
||||
|
||||
return converters;
|
||||
}
|
||||
@@ -85,6 +86,24 @@ public abstract class ThreeTenBackPortConverters {
|
||||
.contains(type);
|
||||
}
|
||||
|
||||
public static enum LocalDateTimeToJsr310LocalDateTimeConverter
|
||||
implements Converter<LocalDateTime, java.time.LocalDateTime> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.core.convert.converter.Converter#convert(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public java.time.LocalDateTime convert(LocalDateTime source) {
|
||||
|
||||
Date date = toDate(source.atZone(ZoneId.systemDefault()).toInstant());
|
||||
|
||||
return source == null ? null : Jsr310Converters.DateToLocalDateTimeConverter.INSTANCE.convert(date);
|
||||
}
|
||||
}
|
||||
|
||||
public static enum DateToLocalDateTimeConverter implements Converter<Date, LocalDateTime> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
Reference in New Issue
Block a user