GWT-Jackson-APT不会忽略序列化中的接口对象

问题描述 投票:2回答:1

我有一个类对象,其中包含一个用于回调的接口变量,我不想将其序列化为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忽略这个界面的最佳方法是什么?或者我是否必须完全重新定义所有对象以删除我的回调函数引用?

java gwt gwt-jackson-apt
1个回答
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,而忽略的字段也不会包含在生成的序列化器中。

© www.soinside.com 2019 - 2024. All rights reserved.