Search code examples
javagwtgwt-jackson-apt

GWT-Jackson-APT not ignoring interface object from serialization


I have a class object that contains an interface variable used for callbacks that I don't want serialized into the JSON. I have attempted to use the @JsonIgnoreProperties() annotation to make it ignore the interface variable, but so far no luck. The pre-processor is choking with a IllegalArgumentException Couldn't make a guess for CallbackRun...

The interface looks generally like:

public interface callbackRun {
    void runOnFinish();
}

With the broad strokes shape of my class defined as:

@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 */

}

What is the best method of getting GWT-jackson-APT to ignore this interface? Or do I have to completely redefine all my objects to remove my callback function references?


Solution

  • You can use @JsonIgnore by annotating the field

    @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 */
    
    }
    

    The field will not be serialized when writing object to JSON and it will be ignored when reading object from JSON. You can always check the generated mappers and you will see a method initIgnoredProperties in the generated deserializer, also the ignored field will not be included in the generated serializer.