DATACMNS-773 - Added support for persisting ZoneId instances as Strings.
We now ship converters for JSR-310 and ThreeTenBP's ZoneId conversion to String and back.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2015 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.
|
||||
@@ -23,6 +23,7 @@ import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -63,6 +64,8 @@ public abstract class Jsr310Converters {
|
||||
converters.add(LocalTimeToDateConverter.INSTANCE);
|
||||
converters.add(DateToInstantConverter.INSTANCE);
|
||||
converters.add(InstantToDateConverter.INSTANCE);
|
||||
converters.add(ZoneIdToStringConverter.INSTANCE);
|
||||
converters.add(StringToZoneIdConverter.INSTANCE);
|
||||
|
||||
return converters;
|
||||
}
|
||||
@@ -156,4 +159,26 @@ public abstract class Jsr310Converters {
|
||||
return source == null ? null : Date.from(source.atZone(systemDefault()).toInstant());
|
||||
}
|
||||
}
|
||||
|
||||
@WritingConverter
|
||||
public static enum ZoneIdToStringConverter implements Converter<ZoneId, String> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public String convert(ZoneId source) {
|
||||
return source.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@ReadingConverter
|
||||
public static enum StringToZoneIdConverter implements Converter<String, ZoneId> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public ZoneId convert(String source) {
|
||||
return ZoneId.of(source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.threeten.bp.Instant;
|
||||
import org.threeten.bp.LocalDate;
|
||||
import org.threeten.bp.LocalDateTime;
|
||||
import org.threeten.bp.LocalTime;
|
||||
import org.threeten.bp.ZoneId;
|
||||
|
||||
/**
|
||||
* Helper class to register {@link Converter} implementations for the ThreeTen Backport project in case it's present on
|
||||
@@ -67,6 +68,8 @@ public abstract class ThreeTenBackPortConverters {
|
||||
converters.add(LocalTimeToDateConverter.INSTANCE);
|
||||
converters.add(DateToInstantConverter.INSTANCE);
|
||||
converters.add(InstantToDateConverter.INSTANCE);
|
||||
converters.add(ZoneIdToStringConverter.INSTANCE);
|
||||
converters.add(StringToZoneIdConverter.INSTANCE);
|
||||
|
||||
return converters;
|
||||
}
|
||||
@@ -161,4 +164,26 @@ public abstract class ThreeTenBackPortConverters {
|
||||
return source == null ? null : toDate(source.atZone(systemDefault()).toInstant());
|
||||
}
|
||||
}
|
||||
|
||||
@WritingConverter
|
||||
public static enum ZoneIdToStringConverter implements Converter<ZoneId, String> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public String convert(ZoneId source) {
|
||||
return source.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@ReadingConverter
|
||||
public static enum StringToZoneIdConverter implements Converter<String, ZoneId> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public ZoneId convert(String source) {
|
||||
return ZoneId.of(source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user