GWT-Jackson-APT 没有从序列化中忽略接口对象

我有一个类对象,其中包含一个接口变量,用于我不想序列化为 JSON 的回调。我试图使用@JsonIgnoreProperties()注释使其忽略接口变量,但到目前为止还没有运气。预处理器因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 忽略此接口的最佳方法是什么?还是我必须完全重新定义我的所有对象才能删除我的回调函数引用?


温温酱
浏览 98回答 1
1回答

Smart猫小萌

您可以@JsonIgnore通过注释字段来使用@JSONMapperpublic class itemInventory {&nbsp; &nbsp; public static itemInventory_MapperImpl MAPPER = new itemInventory_MapperImpl();&nbsp; &nbsp; private static final List<item> itemList = new ArrayList<>();&nbsp; &nbsp; @JsonIgnore&nbsp; &nbsp; private callbackRun responseHandler = null;&nbsp; &nbsp; / * other variables, getters setters here */}将对象写入 JSON 时该字段不会被序列化,从 JSON 读取对象时该字段将被忽略。您始终可以检查生成的映射器,您将initIgnoredProperties在生成的反序列化器中看到一个方法,而且被忽略的字段也不会包含在生成的序列化器中。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java