Skip to content

Commit

Permalink
Merge pull request #5 from Ecwid/2.9.1-ecwid-4
Browse files Browse the repository at this point in the history
Adapt for jdk 21
  • Loading branch information
turchenkoalex authored Apr 17, 2024
2 parents 027498b + 2e20abc commit 193f60b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
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

0 comments on commit 193f60b

Please sign in to comment.