Jackson
Annotations
@JsonManagedReference
- 被其註解的属性可正常序列化
@JsonBackReference
- 被其註解的屬性序列化時會被忽略掉,且只能用於普通 bean,不能是集合、Map、陣列、枚舉。
@JsonInclude
- 告訴
Jackson滿足特定條件,不對該Property進行序列化
@JsonInclude(JsonInclude.Include.NON_DEFAULT)Include.ALWAYS(Default) : 總是包含所有properties,null和空字符串都會序列化Include.NON_DEFAULT: 排除值為null的properties
@JsonProperty
- 將該欄位(屬性)序列化為指定名稱
@JsonPropertyOrder
- 可決定
Entity Serializer時,Properties順序
@JsonFormat
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime created_at;Enum: 枚舉 只能序列化,不能反序列化
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum Categories {
}@JsonIgnoreProperties
- 忽略不存在欄位,也可指定要忽略的欄位
@JsonIgnoreProperties(ignoreUnknown = true)
public class Model{
//...
}@JsonAnyGetter
- 用於可變的
Map,將Key/Value轉為可擴展的Properties
@JsonValue
- 取得標註的Property的Value
@JsonRawValue
- 標註的
Property, Method,序列化時不會有`escaping() or decoration