-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
JDK21 toJson failure #2689
Comments
The relevant JDK enhancement is JDK-8284840 - CLDR update to version 42.0. See also https://bugs.openjdk.org/browse/JDK-8324308 (and friends), for similar issues. |
Gson unfortunately uses a human-readable date format by default. We noticed the same (or a very similar issue) you are seeing here in Gson's unit tests: #2450 There is the idea to possibly change the default date format used by Gson in future versions, see #2472, but it is unclear if that will happen since it could be considered backward incompatible. The best solution at the moment might be to specify a custom date format with |
It seems like this is a destructive way of modification. The application that I have already launched will be affected by setDateFormat. For example, if I toJSON some data into Redis and then fromJson to an object when using it, when some data is written by the node using setDateFormat, an exception will occur when other nodes read it. It is impossible to smoothly upgrade. Of course, for Redis, I can switch to another database to solve the problem. If it is stored in other databases such as MySQL, historical data will be seriously affected! |
Another solution could be to write a Here is a sample implementation for this:
|
Thank you for your guidance. I will proceed with the relevant attempts. |
I got a similar error when working on JDK21 and Gson, Gson doesn't success to parse Level class: Gson gson = new GsonBuilder().disableHtmlEscaping().create(); error |
@brachaA, can you please provide the full exception message, and ideally a small complete code sample for reproducing this? Additionally, it might be better to create a separate GitHub issue first until we are sure that they are the same underlying problem, to avoid that this issue here becomes off-topic. |
Gson version
version 2.10.1
Using JDK 21 to perform fromJson, the Date type contains hidden characters causing the failure of the toJson operation.
In GitHub issues, it seems that I cannot illustrate it, so I will use images to show
Java / Android version
jdk21
Used tools
Description
Expected behavior
Actual behavior
Reproduction steps
1.Convert an object containing a date variable to JSON.
2.Copy the output JSON string.
3.When pasted into an editor like IntelliJ IDEA, hidden characters appear with JDK 21, while JDK 17 does not exhibit this behavior for such operations.
Exception stack trace
The text was updated successfully, but these errors were encountered: