0
我們有一個代表某種配置的結構。我們有一個錯字週期性,錯誤拼寫爲'o'期* o *城市。下面的示例源是已更正的。但是,我需要能夠讀取舊的配置文件以保持向後兼容性。JSON傑克遜,如何使用只讀屬性別名向後兼容?
我可以讓JSON傑克遜識別拼寫錯誤的字段/反序列化屬性,但在序列化時忽略它嗎?
我們使用JSON傑克遜版本2.6.6。
package foo;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@JsonInclude(Include.NON_EMPTY)
@JsonIgnoreProperties(ignoreUnknown = true)
public class Rule {
private LogPeriodicity periodicityLevel;
private Integer periodicity;
// ctors and some other methods omitted for brevity
public LogPeriodicity getPeriodicityLevel() {
return periodicityLevel;
}
public void setPeriodicityLevel(LogPeriodicity periodicityLevel) {
this.periodicityLevel = periodicityLevel;
}
public Integer getPeriodicity() {
return periodicity;
}
public void setPeriodicity(Integer periodicity) {
this.periodicity = periodicity;
}
}
做我已經使用了'@ JsonSetter'註釋拼寫錯誤的setter和它爲我工作得很好。謝謝! – wilx