-
-
Notifications
You must be signed in to change notification settings - Fork 240
Open
Description
With this kind of POJO :
public class Cage
{
public String id;
public String type;
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type",
include = JsonTypeInfo.As.EXTERNAL_PROPERTY)
@JsonSubTypes({
@JsonSubTypes.Type(value = Cat.class, name = "CAT"),
@JsonSubTypes.Type(value = Dog.class, name = "DOG")
})
public Animal animal;
}
public abstract class Animal { }
public class Cat extends Animal {
public String firstName = "My name is cat";
}
public class Dog extends Animal {
public String lastName = "My name is dog";
}When I serialize this :
Cage cage = new Cage();
cage.id = "123";
cage.type = "CAT";
cage.animal = new Cat();
String xml1 = MAPPER.writeValueAsString(cage);
System.out.println(xml1);I get the following result (the property type is duplicated) :
<Cage>
<animal>
<firstName>My name is cat</firstName>
</animal>
<type>CAT</type>
<id>123</id>
<type>CAT</type>
</Cage>Wouldn't be the expected result ?
<Cage>
<animal>
<firstName>My name is cat</firstName>
</animal>
<id>123</id>
<type>CAT</type>
</Cage>Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels