[英]Jackson serialize/deserialize private builder
I'm trying to serialize/deserialize the DynamoDB Record class using Jackson.我正在尝试使用 Jackson 序列化/反序列化DynamoDB 记录class。
I have no control over this class, so I tried to use Jackson mixins.我无法控制这个 class,所以我尝试使用 Jackson mixins。
I did the following:我做了以下事情:
@JsonDeserialize( builder = RecordBuilderMixIn.class )
private abstract static class RecordMixIn
{
}
@JsonPOJOBuilder( withPrefix = "" )
private abstract class RecordBuilderMixIn
{
}
var mapper = new ObjectMapper()
.addMixIn( Record.Builder.class, RecordBuilderMixIn.class )
.addMixIn( Record.class, RecordMixIn.class );
But I get the following error when I do mapper.readValue(json, Record.class);
但是当我执行
mapper.readValue(json, Record.class);
时出现以下错误: :
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Builder class `com.surecloud.jackson.RecordObjectMapper$RecordBuilderMixIn` does not have build method (name: 'build')
Any ideas on how to solve this?关于如何解决这个问题的任何想法?
Thanks谢谢
Add a constructor in RecordBuilderMixIn it is needed for the reflection that the object mapper uses to populate the object.在 RecordBuilderMix 中添加一个构造函数,object 映射器用来填充 object 的反射需要它。
@JsonPOJOBuilder( withPrefix = "" )
private abstract class RecordBuilderMixIn {
public RecordBuilderMixIn() {
// constructor required by java reflection
}
}
Also stop adding new line for the curybrackets after the method declaration it will just cause problems since no modern editors use this style.也停止在方法声明后为括号添加新行,这只会导致问题,因为没有现代编辑器使用这种风格。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.