杰克逊:如果房产丢失怎么办? [英] Jackson: What happens if a property is missing?

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

问题描述

如果我使用 @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?

推荐答案

程序员 Bruce 总结优秀答案href="https://stackoverflow.com/a/8321255/14731">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天全站免登陆