-
Notifications
You must be signed in to change notification settings - Fork 544
fix bug for TypeUtils.castToTimestamp, for issue #3906 and #3907 #3908
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -546,11 +546,11 @@ public static BigInteger castToBigInteger(Object value) { | |||||
| return com.alibaba.fastjson2.util.TypeUtils.toBigInteger(value); | ||||||
| } | ||||||
|
|
||||||
| public static Timestamp castToTimestamp(final Object value) { | ||||||
| public static Object castToTimestamp(final Object value) { | ||||||
| return com.alibaba.fastjson2.util.TypeUtils.cast(value, Timestamp.class); | ||||||
| } | ||||||
|
|
||||||
| public static java.sql.Date castToSqlDate(final Object value) { | ||||||
| public static Object castToSqlDate(final Object value) { | ||||||
|
||||||
| public static Object castToSqlDate(final Object value) { | |
| public static java.sql.Date castToSqlDate(final Object value) { |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,13 @@ | ||||||
| package com.alibaba.fastjson2; | ||||||
|
|
||||||
| import com.alibaba.fastjson.util.TypeUtils; | ||||||
| import org.junit.jupiter.api.Test; | ||||||
|
|
||||||
| import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||||||
|
|
||||||
| public class Issue3906 { | ||||||
| @Test | ||||||
| public void test() throws NoSuchMethodException { | ||||||
|
||||||
| public void test() throws NoSuchMethodException { | |
| public void test() { |
Copilot
AI
Dec 15, 2025
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.
The test has two issues:
- It only verifies that no exception is thrown, but doesn't verify that the conversion actually produces a correct
Timestampobject. Consider adding assertions to verify the result is not null, is an instance ofjava.sql.Timestamp, and has the same time value as the input. - The PR description mentions fixing both issue [BUG]fastjson兼容包报错,2.0.60版本,使用TypeUtils转换java.util.Date为Timestamp报错,1.2.83版本则是正常的 #3906 and [BUG]二方包里使用com.alibaba.fastjson.util.TypeUtils#castToTimestamp时,升级fastjson版本不兼容 #3907, but only includes a test for
castToTimestamp. Add a similar test case forcastToSqlDateto ensure the fix works for both methods.
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.
Changing the return type from
TimestamptoObjectis a breaking API change that will cause compilation errors for existing code. While this may match version 1.2.83's signature, it breaks type safety and forces callers to cast the result. Consider keeping the return type asTimestampto maintain backward compatibility, or document this as a breaking change in the release notes.