DTO示例
@Data
@Accessors(chain = true)
@TableName(value = "publisher_overview_report")
public class OverviewReportModel {
@JsonInclude(JsonInclude.Include.ALWAYS)
private Long engagementUsers;
@JsonInclude(JsonInclude.Include.ALWAYS)
private Float engagementRate;
@JsonIgnore
private Float arpu;
}
第一种方法,在代码中添加注释
不管属性是否为null,都进行返回
@JsonInclude(JsonInclude.Include.ALWAYS)
private Long engagementUsers;
@JsonInclude(JsonInclude.Include.ALWAYS)
private Float engagementRate;
忽略属性返回->隐藏指定属性
@JsonIgnore
private Float arpu;
第二种方法 yml配置文件中进行配置
spring:
jackson:
# json 序列化排除值为 null 的属性
default-property-inclusion: non_null