- 这几天遇到一个自己埋的坑 :<( , 一个 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;
}