The specified field is not returned: @JsonIgnore
encapsulated class
@Data
public class User {
private int id;
private String username;
/**
* @JsonIgnore
* 此注解是类注解,作用是json在序列化时将java bean 中的一些属性忽略掉,序列化和反序列化都受影响
* 生成json时不生成pwd属性
*/
@JsonIgnore
private String pwd;
public User(){
}
public User(int id,String username,String pwd){
this.id=id;
this.username=username;
this.pwd=pwd;
}
}
The json data returned when the api interface is called:
Specify date format
Empty fields are not returned
Specify an alias
Package class:
@Data
public class Video implements Serializable {
private int id;
private String title;
@JsonInclude(JsonInclude.Include.NON_NULL)
private String summary;
private int price;
@JsonInclude(JsonInclude.Include.NON_NULL)
private String coverImg;
//返回指定的别名
@JsonProperty("create_time")
// 返回指定的时间格式
@JsonFormat(pattern ="yyyy-MM-dd hh:mm:ss",locale="zh",timezone = "GMT+8")
private Date createTime;
@JsonInclude(JsonInclude.Include.NON_NULL)
private List<Chapter> chapterList;
public Video(){
} //无参构造
public Video(int id,String title){
this.id =id;
this.title =title;
this.createTime =new Date();
}
}
The calling interface shows: