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

Oha*_*ita 5 java jackson mapper deserialization

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

Jackson 支持这种行为的唯一功能是原语:

final DeserializationConfig.Feature failOnPremitives = DeserializationConfig.Feature.FAIL_ON_NULL_FOR_PRIMITIVES;
Run Code Online (Sandbox Code Playgroud)

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

任何帮助都受到高度赞赏

EM-*_*ons 4

有一个选项称为: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
Run Code Online (Sandbox Code Playgroud)

这适用于所有类型,字符串,整数,双精度数等。