1、时间格式化注解
- Jackson- @JsonFormat:
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime createTime;
- FastJSON - @JSONField:
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime createTime;
2、忽略字段注解
放在字段上或get方法上都可
- Jackson- @JsonIgnore:
@JsonIgnore
private LocalDateTime createTime;
或
@JsonIgnore
public LocalDateTime getCreateTime() {
return createTime;
}
- FastJSON - @JSONField:
@JSONField(serialize = false)
private LocalDateTime createTime;
或
@JSONField(serialize = false)
public LocalDateTime getCreateTime() {
return createTime;
}
注意:
1)SpringBoot中 @RestController 或 @ResponseBody 默认使用的是 Jackson进行JSON序列化;
2)JSON序列化时,实际是调用实体类的 get() 方法获取数据;
3、映射别名
这样在使用JSON.parseObject()的时候, 就能将access_token字段赋值到accessToken,避免手动set
- FastJSON
@JSONField(name = "access_token")
private String accessToken;