实体类序列化JSON时,过滤掉为空的字段的方法
json
适用于现代 C++ 的 JSON。
项目地址:https://gitcode.com/gh_mirrors/js/json

·
实体类序列化JSON时,过滤掉为空的字段的方法
在做一个接口返回数据时,其中一组数据的某个值为null,需要屏蔽掉这个字段,但是其他数据内的字段照常显示,考虑到两个方向,一个是在代码中,把为空的数据字段过滤掉,另一个是通过相应的注解来在实体类层面解决此问题。
考虑到本人比较懒,想找个比较简便的方法,最后还是选择了使用Jackson的一个注解来完成此操作。
@JsonInclude(Include.NON_NULL),此注解的作用就是实体转json,属性值为NULL或者为空时,该属性不参与序列化。
将该标记放在属性上,如果该属性为NULL则不参与序列化,如果放在类上边,那对这个类的全部属性起作用。
//Include.Include.ALWAYS 默认//Include.NON_DEFAULT 属性为默认值不序列化//Include.NON_EMPTY 属性为 空(“”) 或者为 NULL 都不序列化//Include.NON_NULL 属性为NULL 不序列化




适用于现代 C++ 的 JSON。
最近提交(Master分支:17 天前 )
230bfd15
Bumps [actions/dependency-review-action](https://github.com/actions/dependency-review-action) from 4.6.0 to 4.7.0.
- [Release notes](https://github.com/actions/dependency-review-action/releases)
- [Commits](https://github.com/actions/dependency-review-action/compare/ce3cf9537a52e8119d91fd484ab5b8a807627bf8...38ecb5b593bf0eb19e335c03f97670f792489a8b)
---
updated-dependencies:
- dependency-name: actions/dependency-review-action
dependency-version: 4.7.0
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 5 天前
e9391dc5
Bumps [lukka/get-cmake](https://github.com/lukka/get-cmake) from 4.0.1 to 4.02.
- [Release notes](https://github.com/lukka/get-cmake/releases)
- [Commits](https://github.com/lukka/get-cmake/compare/57c20a23a6cac5b90f31864439996e5b206df9dc...ea004816823209b8d1211e47b216185caee12cc5)
---
updated-dependencies:
- dependency-name: lukka/get-cmake
dependency-version: '4.02'
dependency-type: direct:production
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 7 天前
更多推荐
所有评论(0)