Search code examples
javajacksonmixins

Error when using with annotation Mixins with ObjectMapper


I am trying to create a mixin for one of my POJO's, with this code:

interface CustomerStatsIgnoreMixIn {
    @JsonIgnoreProperties({"ref"});
}

public class CustomerStatsJob extends Job {
    private void updateCustomer(Customer customer) {
        ObjectMapper mapper = new ObjectMapper();
        mapper.getSerializationConfig().addMixInAnnotations(Customer.class,
                CustomerStatsIgnoreMixIn.class);
    }
}

I'm getting the follow error in Eclipse on the line @JsonIgnoreProperties({"ref"});

Multiple markers at this line - Syntax error, insert "enum Identifier" to complete EnumHeaderName - Syntax error, insert "EnumBody" to complete EnumDeclaration

I'm sure it's something silly but any ideas what the problem is?


Solution

  • The JsonIgnoreProperties annotation is a Type annotation... it should go right above the interface definition line rather than in the body of the interface.

    Like:

    @JsonIgnoreProperties({"ref"});
    interface CustomerSTatesIgnoreMixin {
    

    Hope this helps.