users@jersey.java.net

[Jersey] Forcing Jackson to ignore 'type' properties for polymorphic types with Jersey

From: Julien Dreux <jdreux_at_justlexit.com>
Date: Fri, 4 May 2012 16:45:59 -0400

Hi all,

I am using an abstract class to localize my models to different languages.
This is the inheritance chain that I have set up:

//Base model, contains localized fields
public class Restaurant extends LocalizedModel<LocalizedRestaurantData>{

...

}

//Abstract class to support localized fields for all my models
@XmlRootElement
public abstract class LocalizedModel<T extends LocalizedData> {

    private T en;

    public T getEn() {
        return en;
    }
    public void setEn(T en) {
        this.en = en;
    }
    ...
}

//Implementation of the localized fields for the restaurant class.
@XmlRootElement
public class LocalizedRestaurantData extends LocalizedData{

    protected String name;
    protected String address;
        ...
}

This all works fine in my Jersey JSON webservice, except for one thing: All
the instances of the localized property 'en' contain an extra field 'type':

Restaurant JSON:
{
"en": {
        "type": "localizedRestaurantData",
        "address": "1234 Main St.",
        "name": "Tacos Folie"
    },
 ...

This 'type' field is undesired and undesirable especially since it seems to
be also required by jackson when parsing an object. I've added
@JsonIgnoreProperties({"type"}) in my code without success.
*
*
*JULIEN DREUX*
jdreux_at_justlexit.com
514 812-8084
www.justlexit.com