@JsonInclude(Include.NON_NULL)
前端的同事要求说尽量不要有null,可有为空串“” 或者 0 或者 [], 但尽量不要null。
所以@JsonInclude(Include.NON_NULL) 这个注解放在类头上就可以解决。 实体类与json互转的时候 属性值为null的不参与序列化
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@JsonInclude(Include.NON_NULL)
public class WithdrawDetail implements Serializable {
}
或者
WithdrawDetail wd = new WithdrawDetail();
wd.setSerializationInclusion(Include.NON_NULL);
实际效果
全局配置
springMVC.xml
<!-- 默认的注解映射的支持 比如requestMapper之类的 -->
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="objectMapper">
<bean class="com.fasterxml.jackson.databind.ObjectMapper">
<property name="serializationInclusion">
<value type="com.fasterxml.jackson.annotation.JsonInclude.Include">NON_NULL</value>
</property>
</bean>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
--------------spring boot 的配置
只在配置文件加上一个配置
spring.jackson.default-property-inclusion=non_null
@JsonInclude(Include.NON_NULL)的更多相关文章
- @JsonInclude(JsonInclude.Include.NON_NULL) 加在对象上
@JsonInclude(JsonInclude.Include.NON_NULL) public class ViewWorkermessage implements Serializable { ...
- @JsonInclude(Include.NON_NULL) resttemplate 传递实体参数时 序列化为json时 空字符串不参与序列化
@JsonInclude(Include.NON_NULL) resttemplate 传递实体参数时 序列化为json时 空字符串不参与序列化 https://www.cnblogs.com/sup ...
- 练习:将值是null的数据删除掉(剔除):com.fasterxml.jackson.annotation.JsonInclude;包
练习:将值是null的数据删除掉(剔除):com.fasterxml.jackson.annotation.JsonInclude;包 例如,有数据是null,不想展示 { "statusC ...
- jackSon注解– @JsonInclude 注解不返回null值字段
@Data @JsonInclude(JsonInclude.Include.NON_NULL) public class OrderDTO { private String orderId; @Js ...
- Jackson 转换JSON,SpringMVC ajax 输出,当值为null或者空不输出字段@JsonInclude
当我们提供接口的时候, Ajax 返回的时候,当对象在转换 JSON (序列化)的时候,值为null或者为“” 的字段还是输出来了.看上去不优雅. 现在我叙述三种方式来控制这种情况. 注解的方式( @ ...
- jackson学习之五:JsonInclude注解
欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...
- java @ResponseBody返回值中去掉NULL字段
需要同时添加两个位置: 1.annotation-driven过滤 <mvc:annotation-driven> <mvc:message-converters register- ...
- spring mvc 删除返回字符串中值为null的字段
在spring的配置文件中进行一下配置: <bean class="org.springframework.web.servlet.mvc.method.annotation.Requ ...
- 【转】从MVC到前后端分离
1. 理解MVC MVC是一种经典的设计模式,全名为Model-View-Controller,即模型-视图-控制器. 其中,模型是用于封装数据的载体,例如,在Java中一般通过一个简单的POJO(P ...
随机推荐
- popstate实现history路由拦截,监听页面返回事件
1.当活动历史记录条目更改时,将触发popstate事件. 如果被激活的历史记录条目是通过对history.pushState()的调用创建的, 或者受到对history.replaceState() ...
- 网络管理 SNMP基础知识
SNMP Agent快速开发 网友:SmileWolf 发布于: 2007.08.02 16:06 (共有条评论) 查看评论 | 我要评论 摘自 http:/ ...
- 浅谈BeanUtils的拷贝,深度克隆
1.BeanUtil本地简单测试在项目中由于需要对某些对象进行深度拷贝然后进行持久化操作,想到了apache和spring都提供了BeanUtils的深度拷贝工具包,自己写了几个Demo做测试,定义了 ...
- plt-3D打印1
plt-3D打印 import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D ...
- [Linux][Ubuntu18.04.1] nginx+php+MySQL环境搭建
说在前面 今天在腾讯云的CVM服务器搭建了一下环境[主机:标准型S2,Unbuntu18.04的LST版本] 采用了nginx服务器(Nginx 静态处理性能比 Apache高3倍以上,不过apach ...
- rest api load test
1. SoapUI + LoadUI 2. https://github.com/jeffbski/bench-rest 3. JMeter
- day6 random随机数模块
random 我们经常看到网站的随机验证码,这些都是由随机数生成的,因此我们需要了解一下随机数的模块.如何生成随机数. random 生成随机数 random.random() 生成0- ...
- vs 单元测试
vs 2010 NOget 包 安装NUnitTDNet,下载TestDriven.NET(http://www.testdriven.net/). 准备动作 先到http://www.testdri ...
- mp4文件数据格式解析
unsigned int(32)[3] 32*3bit string[32] 32*8bit class VisualSampleEntry(codingname) extends Sampl ...
- SASS详解之混合(mixins)
SASS详解之混合(mixins)可以出现在SASS的任何地方.有很多类名具有相同或者相似的样式,就可以用SASS中的混合(mixins)来进行编写,然后针对不同类名的不同样式逐一编写. 定义一个混合 ...