Jackson 2.5 – JsonMappingException: Missing external type id property

I have this class with an External Property “contentType”:

public class ContentEvent implements AbstractMessagingEvent{
    @Valid
    @JsonTypeInfo(include = JsonTypeInfo.As.EXTERNAL_PROPERTY, use = NAME, property = "contentType")
    public final ContentValue message;

    public ContentEvent(ContentValue message) {
        this.message = message;
    }

    public ContentEvent() {
        this(null);
    }

    public static ContentEvent example () {
        return new ContentEvent(HostedFile.example());
    }
}

“contentType” can be one of the following:

@JsonSubTypes({
        @JsonSubTypes.Type(SecureFormSubmission.class),
        @JsonSubTypes.Type(SecureFormInvitation.class),
        @JsonSubTypes.Type(TextPlain.class),
        @JsonSubTypes.Type(HostedFile.class),
        @JsonSubTypes.Type(ExternalFile.class)
})
public interface ContentValue{
}

When I try to deserialize a JSON which is missing the “contentType” field, I get the following error:

com.fasterxml.jackson.databind.JsonMappingException: Missing external type id property ‘contentType’

I tried adding a ‘defaultImpl=NoClass.class’ and also a defaultImpl=MyOwnCustomClass’ and it clears the error, but the result is an object without any ‘contentType’.

What I want is in case the ‘contentType’ field is missing, to use a default.

Thanks in advance.

You can annotate the class with @JsonIgnoreProperties(ignoreUnknown=true).