gpt4 book ai didi

java - Jackson Mapper - 如何在 null 或空值上失败

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:49:23 25 4
gpt4 key购买 nike

我们在代码中使用 Jackson JSON 映射器来反序列化一些配置对象。我们希望 Jackson 在特定字段缺失或为空时反序列化失败

Jackson 中支持这种行为的唯一特性是原语:

final DeserializationConfig.Feature failOnPremitives = DeserializationConfig.Feature.FAIL_ON_NULL_FOR_PRIMITIVES;

问题是有问题的字段主要是字符串

非常感谢任何帮助

最佳答案

有一个名为:FAIL_ON_NULL_FOR_CREATOR_PARAMETERS 的选项。

所以我假设它可以在以下位置访问:DeserializationConfig.Feature.FAIL_ON_NULL_FOR_CREATOR_PARAMETERS;

或者在yml中:

jackson:
serialization:
indent-output: false
deserialization:
fail-on-unknown-properties: true
fail-on-missing-creator-properties: true
fail-on-null-creator-properties: true

这适用于所有类型,字符串、整数、 double 等。

关于java - Jackson Mapper - 如何在 null 或空值上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46388774/

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