在序列化MyObject時,我想在運行時決定屬性類中包含或不包含空屬性。什麼是最好的方法來做到這一點?在運行時設置序列化屬性
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class MyObject {
private String property1;
private DateTime property2;
private Attributes attributes;
}
@Data
public class Attributes {
private String property1;
private String property2;
}
但我需要做條件包括null只在'Attributes'類中,而不在'MyObject'類中。 – Shikhar