FasterXML / FasterXML/jackson-dataformat-xml

Support XML element name based on runtime type

Offen
#679 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Java
Sterne
631
Forks
246
Ø Merge
7 T. 9 Std.
Gemergte PRs (30 T.)
13

Beschreibung

XSD schema's support a way to name an element based on its runtime type through [*substitution groups*](https://www.w3.org/TR/xmlschema-1/#key-equivalenceClass). I'm trying to deserialise such a substitution group. Is this supported in some way?

Example. Suppose there is two types of `Animal`s: `Cow`s and `Goat`s. Based on their type, I want their element to be named either `cow` or `goat`. This would be modelled as follows:

XSD:
``` xml









```

XML example instances:
``` xml

```
``` xml

```

Java model:
``` java
@XmlRootElement(name="document")
public class Document {
private Animal animal;

public Animal getAnimal() {
return animal;
}
public void setAnimal(Animal animal) {
this.animal = animal;
}
}

public class Animal {
@JacksonXmlProperty(isAttribute = true)
private String name;

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

public class Cow extends Animal {}

public class Goat extends Animal {}
```

Is there a way of annotating the classes to get the desired behaviour?

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.