{"id":106,"date":"2023-02-18T09:48:45","date_gmt":"2023-02-18T01:48:45","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=106"},"modified":"2023-02-18T09:49:17","modified_gmt":"2023-02-18T01:49:17","slug":"jackson-null-serialize","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/18\/jackson-null-serialize\/","title":{"rendered":"Jackson\u5b9e\u4f53\u4e3aNULL\u6216\u8005\u4e3a\u7a7a\u4e0d\u663e\u793a"},"content":{"rendered":"<h2>\u5b9e\u4f53\u4e0a<\/h2>\n<pre><code class=\"language-java\">@JsonInclude(JsonInclude.Include.NON_NULL)<\/code><\/pre>\n<p>\u5c06\u8be5\u6ce8\u89e3\u653e\u5728\u5c5e\u6027\u4e0a\uff0c\u5982\u679c\u8be5\u5c5e\u6027\u4e3anull\u5219\u4e0d\u53c2\u4e0e\u5e8f\u5217\u5316\uff1b\u5982\u679c\u653e\u5728\u7c7b\u4e0a\u8fb9\uff0c\u90a3\u5bf9\u8fd9\u4e2a\u7c7b\u7684\u5168\u90e8\u5c5e\u6027\u8d77\u4f5c\u7528<\/p>\n<ul>\n<li><code>Include.Include.ALWAYS<\/code> \u9ed8\u8ba4 <\/li>\n<li><code>Include.NON_DEFAULT<\/code> \u5c5e\u6027\u4e3a\u9ed8\u8ba4\u503c\u4e0d\u5e8f\u5217\u5316 <\/li>\n<li><code>Include.NON_EMPTY<\/code> \u5c5e\u6027\u4e3a \u7a7a\uff08&quot;&quot;\uff09 \u6216\u8005\u4e3a NULL \u90fd\u4e0d\u5e8f\u5217\u5316 <\/li>\n<li><code>Include.NON_NULL<\/code> \u5c5e\u6027\u4e3aNULL \u4e0d\u5e8f\u5217\u5316<\/li>\n<\/ul>\n<h2>\u4ee3\u7801\u4e0a<\/h2>\n<pre><code class=\"language-java\">ObjectMapper mapper = new ObjectMapper();\n\nmapper.setSerializationInclusion(Include.NON_NULL);<\/code><\/pre>\n<p>\u901a\u8fc7\u8be5\u65b9\u6cd5\u5bf9mapper\u5bf9\u8c61\u8fdb\u884c\u8bbe\u7f6e\uff0c\u6240\u6709\u5e8f\u5217\u5316\u7684\u5bf9\u8c61\u90fd\u5c06\u6309\u6539\u89c4\u5219\u8fdb\u884c\u7cfb\u5217\u5316 <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b9e\u4f53\u4e0a @JsonInclude(JsonInclude.Include.NON_NULL) \u5c06\u8be5\u6ce8\u89e3\u653e\u5728\u5c5e\u6027 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[],"class_list":["post-106","post","type-post","status-publish","format-standard","hentry","category-java-basic"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/106","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=106"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/106\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=106"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=106"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}