序列化在实体类的常用用法

匿名 (未验证) 提交于 2019-12-03 00:03:02
//@JsonIgnoreProperties 后面写上不参与序列化的值 @JsonIgnoreProperties(value = { "id", "segmentId", "createDate", "modifyDate", "isDelete" }) public class Profile { 	private Integer id;  	private String userId; 	//@JsonProperty("userid")指定序列化的名称 	@JsonProperty("userid") 	private Integer outUserId;  	@JsonProperty("truename") 	private String trueName; 	 	@JsonProperty("kidname") 	private String kidName;  	@JsonProperty("alongwith") 	private Byte alongWith;  	@JsonProperty("childscount") 	private Byte childCount;  	@JsonProperty("childgender") 	private Byte childGender; 	//@JsonFormat适用于时间格式上的转化     @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")     private Date regDate; 	} 

或者属性值为空的不参与序列化

    //值为null 不参与序列化     @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)     public class Profile { 	private Integer id;  	private String userId; 	 	@JsonProperty("userid") 	private Integer outUserId;  	@JsonProperty("truename") 	private String trueName; 	 	@JsonProperty("kidname") 	private String kidName;  	@JsonProperty("alongwith") 	private Byte alongWith;  	@JsonProperty("childscount") 	private Byte childCount;  	@JsonProperty("childgender") 	private Byte childGender; 	} 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!