我有一個(gè)類對象,其中包含一個(gè)接口變量,用于我不想序列化為 JSON 的回調(diào)。我試圖使用@JsonIgnoreProperties()注釋使其忽略接口變量,但到目前為止還沒有運(yùn)氣。預(yù)處理器因IllegalArgumentException 窒息而無法猜測 CallbackRun ...界面大致如下:public interface callbackRun { void runOnFinish();}我班級的粗筆畫形狀定義為:@JSONMapper@JsonIgnoreProperties(ignoreUnknown=true)public class itemInventory { public static itemInventory_MapperImpl MAPPER = new itemInventory_MapperImpl(); private static final List<item> itemList = new ArrayList<>(); private callbackRun responseHandler = null; / * other variables, getters setters here */}讓 GWT-jackson-APT 忽略此接口的最佳方法是什么?還是我必須完全重新定義我的所有對象才能刪除我的回調(diào)函數(shù)引用?
1 回答

Smart貓小萌
TA貢獻(xiàn)1911條經(jīng)驗(yàn) 獲得超7個(gè)贊
您可以@JsonIgnore通過注釋字段來使用
@JSONMapper
public class itemInventory {
public static itemInventory_MapperImpl MAPPER = new itemInventory_MapperImpl();
private static final List<item> itemList = new ArrayList<>();
@JsonIgnore
private callbackRun responseHandler = null;
/ * other variables, getters setters here */
}
將對象寫入 JSON 時(shí)該字段不會(huì)被序列化,從 JSON 讀取對象時(shí)該字段將被忽略。您始終可以檢查生成的映射器,您將initIgnoredProperties在生成的反序列化器中看到一個(gè)方法,而且被忽略的字段也不會(huì)包含在生成的序列化器中。
添加回答
舉報(bào)
0/150
提交
取消