Jackson2 反序列化: setter 方法重载的坑

在使用Jackson2进行反序列化时遇到一个问题,由于setter方法的重载,导致反序列化失败。通过DEBUG跟踪,发现Jackson在处理重载方法时出现了问题。解决方案包括将注解放在特定setter方法上或修改重载方法。作者考虑是否能向Jackson项目提交PR以修复这个问题。
摘要由CSDN通过智能技术生成
  • 这几天遇到一个自己埋的坑 :<( , 一个 bean 中有一个 LocalDateTime 字段, 用了注解或配置相应反序列化器, 都无法序列化, 就是提示错误:
com.fasterxml.jackson.databind.JsonMappingException: Problem deserializing property 'expireTime' (expected type: [simple type, class int]; actual type:
`java.time.LocalDateTime`), problem: argument type mismatch
 at [Source: (String)"{"code":"5ddj","expireTime":"2020-10-31 10:59:44 811","reuse":false,"image":null,"expired":false}"; line: 1, column: 29] (through reference chain:
 top.dcenter.ums.security.core.auth.validate.codes.image.ImageCode["expireTime"])

相关配置:

相关配置

Bean

@Getter
@Setter
@ToString
public class ValidateCode implements Serializable {
   

    private static final long serialVersionUID = 8564646192066649173L;

    private String code;

    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss SSS", locale = "zh", timezone = "GMT+8")
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    private LocalDateTime expireTime;
    /**
     * 是否复用, 如果复用, 不会重新产生验证码, 仍使用验证码失败的验证码
     */
    private Boolean reuse;

    public ValidateCode() {
   
        this.code = null;
        this.expireTime = null;
        this.reuse = false;
    }
    
    /**
     * 验证码构造器: 默认 <pre>reus
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值