1
votes

In my project I have something like this

enum Species {
    DOG, CAT
}

@JsonTypeInfo(
        use = JsonTypeInfo.Id.NAME,
        include = JsonTypeInfo.As.PROPERTY,
        property = "type")
@JsonSubTypes({
        @Type(value = Cat.class, name = "cat"),
        @Type(value = Dog.class, name = "dog") })
class Animal {
    Species species;
    String name;
}

class Cat extends Animal {
    Cat() {
        species = Species.CAT;
    }
    ...
}

class Dog extends Animal {
    Dog() {
        species = Species.DOG;
    }
    ...
}

class Zoo {
    Collection<Animal> animals;
}

I need to serialize/deserialize the zoo to json. I followed this guide http://programmerbruce.blogspot.com/2011/05/deserialize-json-with-jackson-into.html and it worked just fine. But it adds redundant property "type" to json object which I dont really need. Is there any way to serialize/deserialize collection properly just using species property of my pojo?

1

1 Answers

0
votes

The 2.2.0 version of Jackson should have fixed this issue.

You can see details of the issue and the fix for it here: https://github.com/FasterXML/jackson-databind/issues/23