GWT-Jackson-APT无法忽略序列化中的接口对象

时间:2019-02-12 15:03:10

标签: java gwt gwt-jackson-apt

我有一个类对象,该对象包含一个接口变量,该接口变量用于不希望序列化为JSON的回调。我试图使用 @JsonIgnoreProperties() 批注使其忽略接口变量,但到目前为止还算不上什么。预处理程序因 IllegalArgumentException令人cho目结舌 ...

界面通常看起来像:

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忽略此接口的最佳方法是什么?还是我必须完全重新定义所有对象才能删除回调函数引用?

1 个答案:

答案 0 :(得分:2)

您可以通过注释字段来使用@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时,该字段不会序列化,而从JSON读取对象时,该字段将被忽略。您始终可以检查生成的映射器,并且将在生成的反序列化器中看到方法initIgnoredProperties,并且被忽略的字段也不会包含在生成的序列化器中。