我有一个类,我正在尝试将一些JSON反序列化。其中一个属性具有通过@JsonDeserialize注释附加的自定义转换器。当使用setter编写类时,反序列化工作正常,并且setter上的注释如下:
public class Rates extends AbstractResponse {
private Date effectiveDate;
private List<Rate> rates;
public Rates(Date effectiveDate, List<Rate> rates) {
this.effectiveDate = effectiveDate;
this.rates = rates;
}
public Date getEffectiveDate() {
return this.effectiveDate;
}
@JsonProperty("timestamp")
public void setEffectiveDate(Date effectiveDate) {
this.effectiveDate = effectiveDate;
}
@JsonDeserialize(converter = RatesTableConverter.class)
public void setRates(List<Rate> rates) {
this.rates = rates;
}
public List<Rate> getRates() {
return this.rates;
}
}
但是当我重新写它时:
public class Rates extends AbstractResponse {
private final Date effectiveDate;
private final List<Rate> rates;
@JsonCreator
public Rates(
@JsonProperty("timestamp") Date effectiveDate,
@JsonProperty("rates")
@JsonDeserialize(converter = RatesTableConverter.class) List<Rate> rates) {
this.effectiveDate = effectiveDate;
this.rates = rates;
}
public Date getEffectiveDate() {
return this.effectiveDate;
}
public List<Rate> getRates() {
return this.rates;
}
}
我收到此错误:
com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
我已经搞砸了许多想法,无法让它发挥作用。似乎在构造函数上使用时,未正确检查反序列化器。
我错过了哪些想法?