mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-17 16:44:57 +00:00
HHH-13266 Fix LocalDate serialization by using the proper conversion methods between LocalDate and Timestamp
This commit is contained in:
parent
9a8d4f0e5d
commit
1293b5bf70
@ -63,6 +63,13 @@ public <X> X unwrap(LocalDate value, Class<X> type, WrapperOptions options) {
|
||||
final LocalDateTime localDateTime = value.atStartOfDay();
|
||||
|
||||
if ( Timestamp.class.isAssignableFrom( type ) ) {
|
||||
/*
|
||||
* Workaround for HHH-13266 (JDK-8061577).
|
||||
* We could have done Timestamp.from( localDateTime.atZone( ZoneId.systemDefault() ).toInstant() ),
|
||||
* but on top of being more complex than the line below, it won't always work.
|
||||
* Timestamp.from() assumes the number of milliseconds since the epoch
|
||||
* means the same thing in Timestamp and Instant, but it doesn't, in particular before 1900.
|
||||
*/
|
||||
return (X) Timestamp.valueOf( localDateTime );
|
||||
}
|
||||
|
||||
@ -97,7 +104,14 @@ public <X> LocalDate wrap(X value, WrapperOptions options) {
|
||||
|
||||
if ( Timestamp.class.isInstance( value ) ) {
|
||||
final Timestamp ts = (Timestamp) value;
|
||||
return LocalDateTime.ofInstant( ts.toInstant(), ZoneId.systemDefault() ).toLocalDate();
|
||||
/*
|
||||
* Workaround for HHH-13266 (JDK-8061577).
|
||||
* We used to do LocalDateTime.ofInstant( ts.toInstant(), ZoneId.systemDefault() ).toLocalDate(),
|
||||
* but on top of being more complex than the line below, it won't always work.
|
||||
* ts.toInstant() assumes the number of milliseconds since the epoch
|
||||
* means the same thing in Timestamp and Instant, but it doesn't, in particular before 1900.
|
||||
*/
|
||||
return ts.toLocalDateTime().toLocalDate();
|
||||
}
|
||||
|
||||
if ( Long.class.isInstance( value ) ) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user