-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Register Converters for Offset java.time types in Jsr310Converters #2681
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,14 +13,15 @@ | |
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.data.redis.core.convert; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.LocalTime; | ||
import java.time.OffsetDateTime; | ||
import java.time.OffsetTime; | ||
import java.time.Period; | ||
import java.time.ZoneId; | ||
import java.time.ZonedDateTime; | ||
|
@@ -47,9 +48,11 @@ public abstract class Jsr310Converters { | |
Jsr310Converters.class.getClassLoader()); | ||
|
||
/** | ||
* Returns the converters to be registered. Will only return converters in case we're running on Java 8. | ||
* Returns the {@link Converter Converters} to be registered. | ||
* <p> | ||
* Will only return {@link Converter Converters} in case we're running on Java 8. | ||
* | ||
* @return | ||
* @return the {@link Converter Converters} to be registered. | ||
*/ | ||
public static Collection<Converter<?, ?>> getConvertersToRegister() { | ||
|
||
|
@@ -58,6 +61,7 @@ public abstract class Jsr310Converters { | |
} | ||
|
||
List<Converter<?, ?>> converters = new ArrayList<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could be changed to |
||
|
||
converters.add(new LocalDateTimeToBytesConverter()); | ||
converters.add(new BytesToLocalDateTimeConverter()); | ||
converters.add(new LocalDateToBytesConverter()); | ||
|
@@ -74,6 +78,10 @@ public abstract class Jsr310Converters { | |
converters.add(new BytesToPeriodConverter()); | ||
converters.add(new DurationToBytesConverter()); | ||
converters.add(new BytesToDurationConverter()); | ||
converters.add(new OffsetDateTimeToBytesConverter()); | ||
converters.add(new BytesToOffsetDateTimeConverter()); | ||
converters.add(new OffsetTimeToBytesConverter()); | ||
converters.add(new BytesToOffsetTimeConverter()); | ||
|
||
return converters; | ||
} | ||
|
@@ -296,4 +304,51 @@ public Duration convert(byte[] source) { | |
} | ||
} | ||
|
||
/** | ||
* @author John Blum | ||
* @see java.time.OffsetDateTime | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. though not a |
||
*/ | ||
static class OffsetDateTimeToBytesConverter extends StringBasedConverter implements Converter<OffsetDateTime, byte[]> { | ||
|
||
@Override | ||
public byte[] convert(OffsetDateTime source) { | ||
return fromString(source.toString()); | ||
} | ||
} | ||
|
||
/** | ||
* @author John Blum | ||
* @see java.time.OffsetDateTime | ||
*/ | ||
static class BytesToOffsetDateTimeConverter extends StringBasedConverter implements Converter<byte[], OffsetDateTime> { | ||
|
||
@Override | ||
public OffsetDateTime convert(byte[] source) { | ||
return OffsetDateTime.parse(toString(source)); | ||
} | ||
} | ||
|
||
/** | ||
* @author John Blum | ||
* @see java.time.OffsetTime | ||
*/ | ||
static class OffsetTimeToBytesConverter extends StringBasedConverter implements Converter<OffsetTime, byte[]> { | ||
|
||
@Override | ||
public byte[] convert(OffsetTime source) { | ||
return fromString(source.toString()); | ||
} | ||
} | ||
|
||
/** | ||
* @author John Blum | ||
* @see java.time.OffsetTime | ||
*/ | ||
static class BytesToOffsetTimeConverter extends StringBasedConverter implements Converter<byte[], OffsetTime> { | ||
|
||
@Override | ||
public OffsetTime convert(byte[] source) { | ||
return OffsetTime.parse(toString(source)); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can drop the extra
BinaryConverters.
part here.