Jackson

Annotations

@JsonManagedReference

  • 被其註解的属性可正常序列化

@JsonBackReference

  • 被其註解的屬性序列化時會被忽略掉,且只能用於普通 bean,不能是集合、Map、陣列、枚舉。

@JsonInclude

  • 告訴Jackson滿足特定條件,不對該Property進行序列化
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
  • Include.ALWAYS (Default) : 總是包含所有 propertiesnull空字符串 都會序列化
  • Include.NON_DEFAULT : 排除值為 nullproperties

@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