gpt4 book ai didi

java - Lombok v1.6.20 不适用于 Jackson

转载 作者:搜寻专家 更新时间:2023-10-31 19:52:21 25 4
gpt4 key购买 nike

当使用最新的 Lombok v1.6.20 生成的构造函数时,Jackson 无法使用该构造函数。

比如反序列化的时候

@Data
@AllArgsConstructor
private static class TestObject {
private Integer a;
private String b;
}

我得到了

    com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of TestObject: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?)
at [Source: {"a":0,"b":"0"}; line: 1, column: 2]

at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:270)
at com.fasterxml.jackson.databind.DeserializationContext.instantiationException(DeserializationContext.java:1456)
at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1012)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1206)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:314)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:148)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3814)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2858)

它适用于 Lombok 1.6.18。迁移到 Spring Boot 2 时可能会发生此问题。

最佳答案

原因是 Lombok 1.6.20 中的向后不兼容更改。查看 Lombok 变更日志 https://projectlombok.org/changelog和这个错误报告 https://github.com/rzwitserloot/lombok/issues/1563了解更多详情

解决方案是指定 lombok.anyConstructor.addConstructorProperties 配置参数。

关于java - Lombok v1.6.20 不适用于 Jackson,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48749125/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com