-
Notifications
You must be signed in to change notification settings - Fork 546
Open
Labels
Milestone
Description
问题描述
二方包里使用com.alibaba.fastjson.util.TypeUtils#castToTimestamp时,升级fastjson版本不兼容
环境信息
- OS信息: macOS 26.1 (M1 Pro 芯片 )
- JDK信息: jdk 1.8
- 版本信息:com.alibaba:fastjson:2.0.60
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>2.0.60</version>
</dependency>
重现步骤
二方包里fastjson版本为1.2.83,示例代码如下
import com.alibaba.fastjson.util.TypeUtils;
public class FastJsonTest {
public static Object castToTimestamp(Object obj) {
return TypeUtils.castToTimestamp(obj);
}
}在项目中使用二方包里的代码如下
public static void main(String[] args) {
FastJsonTest.castToTimestamp(null);
}当fastjson在项目和二方包里的版本都为1.2.83时,没有任何问题,不会报错;当升级项目中maven版本为2.0.60时,运行上述代码,会报错,报错信息如下
Exception in thread "main" java.lang.NoSuchMethodError: com.alibaba.fastjson.util.TypeUtils.castToTimestamp(Ljava/lang/Object;)Ljava/lang/Object;
at com.example.print.com.excample.FastJsonTest.castToTimestamp(FastJsonTest.java:8)
at org.example.Test2.main(Test2.java:11)
原因是com.alibaba.fastjson.util.TypeUtils#castToTimestamp方法在1.2.83版本返回值类型是Object,而在2.0.60版本则是Timestamp。这个返回值为啥在高版本直接改掉了啊,虽然Timestamp是属于Object,在项目中使用是没问题,一旦涉及到在二方包中使用,就会有上述问题。