杰克逊:如果财产遗失会怎样? [英] Jackson: What happens if a property is missing?

查看:169
本文介绍了杰克逊:如果财产遗失会怎样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用 @JsonProperty 注释构造函数参数会发生什么,但Json没有指定该属性。构造函数得到什么值?

What happens if I annotate a constructor parameter using @JsonProperty but the Json doesn't specify that property. What value does the constructor get?

如何区分具有空值的属性与JSON中不存在的属性?

How do I differentiate between a property having a null value versus a property that is not present in the JSON?

推荐答案

通过程序员布鲁斯总结出色的答案 StaxMan


  1. 构造函数引用的缺失属性被分配了一个默认值由Java定义

您可以使用setter方法来区分隐式或显式设置的属性。仅对具有显式值的属性调用Setter方法。 Setter方法可以跟踪是否使用布尔标志显式设置属性(例如 isValueSet )。

You can use setter methods to differentiate between properties that are implicitly or explicitly set. Setter methods are only invoked for properties with explicit values. Setter methods can keep track of whether a property was explicitly set using a boolean flag (e.g. isValueSet).

这篇关于杰克逊:如果财产遗失会怎样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆