全部,如何讓FasterXMLJackson使用@JsonCreator mixin?
任何人都可以看到我的方式的錯誤?
我需要自定義的反序列化,從JSON,在下拉向導中工作。我跟着一些如何,但它不起作用。結果是我沒有可用的,一個默認的,無參數的構造函數。相反,我有一個工廠方法。我無法修改我試圖反序列化的類。我可以序列化爲JSON序列化&反序列化XML和。但是從JSON反序列化是阻塞。
我已經閱讀了所有我可以在SO和其他地方找到的東西,但沒有任何規定的作品。
我創建一個混合:
public class PatientMixin {
@JsonCreator
public static ForecastPatient createForecastForecastPatient() {
return ForecastFactory.eINSTANCE.createForecastPatient();
}
}
在我的DW Application.run(......)我這樣做:
<code before>
environment.getObjectMapper().addMixIn(ForecastPatient.class, PatientMixin.class);
<code after>
上面應該夠傑克遜找到我的密新和打電話給工廠。相反,我得到一個錯誤:
Can not construct instance of forecast.ForecastPatient, problem: abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information
我會想我有東西映射正常,但顯然不是。此外,我正在閱讀的許多示例似乎都過時了。
在此先感謝
是forecast.ForecastPatient一個抽象類? –
不,它不是抽象的,它是一個接口,其中工廠方法返回一個實現。 ForecastPatient et.al.是由eclipse建模框架生成的。 –
Jackson無法實例化一個接口,您應該告訴jackson您想要實例化的實現 –