Let's say I have a XML structure where one level contains mixed elements, like this:
<bowl>
<banana />
<apple />
<banana />
</bowl>
Using XmlMapper, is there any way of deserialize this to a structure like this?
sealed interface Fruit {
record Banana() implements Fruit {}
record Apple() implements Fruit {}
}
record Bowl(
List<Fruit> fruits
) {
I have been trying the annotations (@JsonTypeInfo, @JsonSubTypes) that I usually use for these situations when decoding JSON, but can't find a combination that works.
Do I have to use a custom deserializer like suggested in this answer, or is there a way to do this using @JsonSubTypes?