Skip to content

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

@dengly

Description

@dengly

问题描述

通过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]

重现步骤

期待的正确结果

能正常解析不报错

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixed

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions