fastjson2 icon indicating copy to clipboard operation
fastjson2 copied to clipboard

[BUG]枚举类型反序列化问题

Open dengly opened this issue 1 year ago • 1 comments

问题描述

通过fastjson 2.x序列化枚举类 和 枚举类型的List后,再反序列化时都会报错,默认都只会找形参是int类型的setter方法,这样会导致错误,即使有多个setter方法且存在形参正确的也没有找到合适的方法,在fastjson 1.x都没有这类问题,错误日志如下:

2024-02-04 09:43:36.050|zzwtec-information-7ff775b8df-sh8zk|172.16.1.252|zzwtec-information|1|http-nio-8084-exec-89|ERROR|org.apache.juli.logging.DirectJDKLog|log|182|1706862525070|Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NumberFormatException: For input string: "["COMMUNITY"]"] with root cause||java.lang.NumberFormatException: For input string: "["COMMUNITY"]"
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
        at java.lang.Integer.parseInt(Integer.java:580)
        at java.lang.Integer.valueOf(Integer.java:766)
        at com.zzwtec.interfaces.information.dto.AdDTO.setObjTypes(AdDTO.java:446)
        at com.alibaba.fastjson2.reader.ORG_4_37_AdDTO.readObject(Unknown Source)
        at com.alibaba.fastjson2.reader.ORG_2_3_RequestObject.readObject(Unknown Source)
        at com.alibaba.fastjson.JSON.parseObject(JSON.java:774)
        at com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter.readType(FastJsonHttpMessageConverter.java:126)
        at com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter.read(FastJsonHttpMessageConverter.java:87)

环境信息

  • OS信息: [e.g.:CentOS Linux 7 (Core)]
  • JDK信息: [e.g.:Openjdk 1.8.0_252]
  • 版本信息:[e.g.:Fastjson2 2.0.46]

重现步骤

期待的正确结果

能正常解析不报错

dengly avatar Feb 04 '24 02:02 dengly

AdDTO这个类方便发出来吗?

rowstop avatar Feb 05 '24 01:02 rowstop

https://github.com/alibaba/fastjson2/releases/tag/2.0.52 问题已修复,请用新版本

wenshao avatar Jul 14 '24 14:07 wenshao