禁用端点的 DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES

问题描述 投票:0回答:1

我正在向应用程序添加一个端点,该端点接收 json,并在 Spring 中自动转换为我创建的 DTO。很多字段可以为 null,我在 Kotlin 中用问号设置,当 json 中缺少值时这不是问题,但问题是当明确存在“null”时。

JSON 解析错误:创建者属性“Trial_period”为空值(索引 6);

DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES
已启用”

由于某种原因在application.yml中设置了

jackson:
 deserialization:
  fail-on-null-creator-properties: true

所以我不想全局更改它,但我需要为此端点禁用它。 我该怎么办?

谢谢你。

spring kotlin jackson null deserialization
1个回答
0
投票

一个选项是在 DTO 中添加注释。

@JsonInclude(JsonInclude.Include.ALWAYS)
private String trial_period;
© www.soinside.com 2019 - 2024. All rights reserved.