Skip to content
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

Adapt for jdk 21 #5

Merged
merged 2 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gson/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.google.code.gson</groupId>
<artifactId>gson-parent</artifactId>
<version>2.9.1-ecwid-3</version>
<version>2.9.1-ecwid-4</version>
</parent>

<artifactId>gson</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions gson/src/main/java/com/google/gson/internal/JavaVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,9 @@ public static boolean isJava9OrLater() {
return majorJavaVersion >= 9;
}

public static boolean isJava20OrLater() {
return majorJavaVersion >= 20;
}

private JavaVersion() { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.google.gson.internal;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Locale;

public class PreJava20DateFormatProvider {
/**
* Compatibility fix for bug: <a href="https://bugs.openjdk.org/browse/JDK-8304925">JDK-8304925</a>
* Space used instead NBSP in format pattern.
*
* @return Returns the same DateFormat as {@code DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.US)}
* in Java 19 or below.
*/
public static DateFormat getUSDateFormat() {
return new SimpleDateFormat("MMM d, y, h:mm:ss a", Locale.US);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.internal.JavaVersion;
import com.google.gson.internal.PreJava20DateFormatProvider;
import com.google.gson.internal.PreJava9DateFormatProvider;
import com.google.gson.internal.bind.util.ISO8601Utils;
import com.google.gson.reflect.TypeToken;
Expand Down Expand Up @@ -65,6 +66,9 @@ public DateTypeAdapter() {
if (JavaVersion.isJava9OrLater()) {
dateFormats.add(PreJava9DateFormatProvider.getUSDateTimeFormat(DateFormat.DEFAULT, DateFormat.DEFAULT));
}
if (JavaVersion.isJava20OrLater()) {
dateFormats.add(PreJava20DateFormatProvider.getUSDateFormat());
}
}

@Override public Date read(JsonReader in) throws IOException {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>com.google.code.gson</groupId>
<artifactId>gson-parent</artifactId>
<version>2.9.1-ecwid-3</version>
<version>2.9.1-ecwid-4</version>
<packaging>pom</packaging>

<name>Gson Parent</name>
Expand Down
Loading