Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Closed
dengly opened this issue Feb 4, 2024 · 2 comments
Closed

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

dengly opened this issue Feb 4, 2024 · 2 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@dengly
Copy link

dengly commented Feb 4, 2024

问题描述

通过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 dengly added the bug Something isn't working label Feb 4, 2024
@rowstop
Copy link
Contributor

rowstop commented Feb 5, 2024

AdDTO这个类方便发出来吗?

wenshao pushed a commit that referenced this issue Jun 8, 2024
* fix prefer to most specified setter method, for issue #2229
@wenshao wenshao added this to the 2.0.52 milestone Jun 8, 2024
@wenshao wenshao added the fixed label Jun 8, 2024
@wenshao
Copy link
Member

wenshao commented Jul 14, 2024

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

@wenshao wenshao closed this as completed Jul 14, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

3 participants