DATACMNS-1294 - Enforce JSR-310 type mapping to java.util.Date.
After considering JSR-310 types to be simple we map these types primarily to java.util.Date as the majority of stores does not natively support JSR-310 types. Converters referencing JSR-310 types are now properly annotated with Reading/WritingConverter annotations to distinguish between reading and writing intents. Othwerise, converters between JSR-310/java.util types and Joda/ThreeTenBackport to JSR-310 types interfere with conversion as regular java.util.Date types would convert to e.g. LocalDateTime.
This commit is contained in:
@@ -31,8 +31,9 @@ import org.springframework.util.ClassUtils;
|
||||
/**
|
||||
* Helper class to register JodaTime specific {@link Converter} implementations in case the library is present on the
|
||||
* classpath.
|
||||
*
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public abstract class JodaTimeConverters {
|
||||
@@ -41,7 +42,7 @@ public abstract class JodaTimeConverters {
|
||||
|
||||
/**
|
||||
* Returns the converters to be registered. Will only return converters in case JodaTime is present on the class.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Collection<Converter<?, ?>> getConvertersToRegister() {
|
||||
@@ -64,6 +65,7 @@ public abstract class JodaTimeConverters {
|
||||
return converters;
|
||||
}
|
||||
|
||||
@ReadingConverter
|
||||
public static enum LocalDateToDateConverter implements Converter<LocalDate, Date> {
|
||||
|
||||
INSTANCE;
|
||||
@@ -127,6 +129,7 @@ public abstract class JodaTimeConverters {
|
||||
}
|
||||
}
|
||||
|
||||
@ReadingConverter
|
||||
public static enum DateToDateMidnightConverter implements Converter<Date, DateMidnight> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@@ -42,6 +42,7 @@ import org.springframework.util.ClassUtils;
|
||||
* @author Oliver Gierke
|
||||
* @author Barak Schoster
|
||||
* @author Jens Schauder
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public abstract class Jsr310Converters {
|
||||
|
||||
@@ -90,6 +91,7 @@ public abstract class Jsr310Converters {
|
||||
.contains(type);
|
||||
}
|
||||
|
||||
@ReadingConverter
|
||||
public static enum DateToLocalDateTimeConverter implements Converter<Date, LocalDateTime> {
|
||||
|
||||
INSTANCE;
|
||||
@@ -100,6 +102,7 @@ public abstract class Jsr310Converters {
|
||||
}
|
||||
}
|
||||
|
||||
@WritingConverter
|
||||
public static enum LocalDateTimeToDateConverter implements Converter<LocalDateTime, Date> {
|
||||
|
||||
INSTANCE;
|
||||
@@ -110,6 +113,7 @@ public abstract class Jsr310Converters {
|
||||
}
|
||||
}
|
||||
|
||||
@ReadingConverter
|
||||
public static enum DateToLocalDateConverter implements Converter<Date, LocalDate> {
|
||||
|
||||
INSTANCE;
|
||||
@@ -120,6 +124,7 @@ public abstract class Jsr310Converters {
|
||||
}
|
||||
}
|
||||
|
||||
@WritingConverter
|
||||
public static enum LocalDateToDateConverter implements Converter<LocalDate, Date> {
|
||||
|
||||
INSTANCE;
|
||||
@@ -130,6 +135,7 @@ public abstract class Jsr310Converters {
|
||||
}
|
||||
}
|
||||
|
||||
@ReadingConverter
|
||||
public static enum DateToLocalTimeConverter implements Converter<Date, LocalTime> {
|
||||
|
||||
INSTANCE;
|
||||
@@ -140,6 +146,7 @@ public abstract class Jsr310Converters {
|
||||
}
|
||||
}
|
||||
|
||||
@WritingConverter
|
||||
public static enum LocalTimeToDateConverter implements Converter<LocalTime, Date> {
|
||||
|
||||
INSTANCE;
|
||||
@@ -150,6 +157,7 @@ public abstract class Jsr310Converters {
|
||||
}
|
||||
}
|
||||
|
||||
@ReadingConverter
|
||||
public static enum DateToInstantConverter implements Converter<Date, Instant> {
|
||||
|
||||
INSTANCE;
|
||||
@@ -160,6 +168,7 @@ public abstract class Jsr310Converters {
|
||||
}
|
||||
}
|
||||
|
||||
@WritingConverter
|
||||
public static enum InstantToDateConverter implements Converter<Instant, Date> {
|
||||
|
||||
INSTANCE;
|
||||
@@ -170,6 +179,7 @@ public abstract class Jsr310Converters {
|
||||
}
|
||||
}
|
||||
|
||||
@ReadingConverter
|
||||
public static enum LocalDateTimeToInstantConverter implements Converter<LocalDateTime, Instant> {
|
||||
|
||||
INSTANCE;
|
||||
@@ -180,6 +190,7 @@ public abstract class Jsr310Converters {
|
||||
}
|
||||
}
|
||||
|
||||
@ReadingConverter
|
||||
public static enum InstantToLocalDateTimeConverter implements Converter<Instant, LocalDateTime> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@@ -38,8 +38,9 @@ import org.threeten.bp.ZoneId;
|
||||
/**
|
||||
* Helper class to register {@link Converter} implementations for the ThreeTen Backport project in case it's present on
|
||||
* the classpath.
|
||||
*
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
* @see <a href="http://www.threeten.org/threetenbp">http://www.threeten.org/threetenbp</a>
|
||||
* @since 1.10
|
||||
*/
|
||||
@@ -50,7 +51,7 @@ public abstract class ThreeTenBackPortConverters {
|
||||
|
||||
/**
|
||||
* Returns the converters to be registered. Will only return converters in case we're running on Java 8.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Collection<Converter<?, ?>> getConvertersToRegister() {
|
||||
|
||||
Reference in New Issue
Block a user