Java模型:
@lombok.Data
public class Foo {
...
private boolean isDefault;
}
序列化为JSON:
{
...,
"isDefault" : true
}
ObjectMapper
配置:
ObjectMapper mapper = new ObjectMapper();
VisibilityChecker<?> vc = objectMapper.getSerializationConfig().getDefaultVisibilityChecker()
.withFieldVisibility(JsonAutoDetect.Visibility.ANY)
.withGetterVisibility(JsonAutoDetect.Visibility.NONE)
.withSetterVisibility(JsonAutoDetect.Visibility.NONE)
.withCreatorVisibility(JsonAutoDetect.Visibility.NONE)
.withIsGetterVisibility(JsonAutoDetect.Visibility.NONE);
mapper.setVisibility(vc);
问题:代码无法将JSON反序列化为java对象,并且UnrecognizedPropertyException
的{{1}}失败,即使它完全将其序列化为JSON。有什么想法?
提前谢谢。