google / google/gson

Date change issue when deserialization by java 8

Open
#1,682 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
24.2k
Forks
4.5k
Avg merge
6d 4h
Merged PRs (30d)
12

Description

This is for the same reason outlined on #1210. #1221 fixed part of the issue. The exception happens when the date is serialized with java after 9 and deserialized with java 8.

A quick fix would be add function to create format for java 8:

public static DateFormat getUSDateTimeFormatAfter9(int dateStyle, int timeStyle) {
String pattern = getDatePartOfDateTimePattern(dateStyle) + ", " + getTimePartOfDateTimePattern(timeStyle); // this format is missing from java 8
return new SimpleDateFormat(pattern, Locale.US);
}

Add this to the dateFormats then java version is before 9.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.