I seemed stuck with the generation of Java classes by XSD.
When we have a few XSD elements placed on the same level which to be converted to Java Object, the JAXB generates a List<Object>.
This issue violates the POJO > XML unmarshaling.
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Animals", propOrder = {
"dogOrCatOrAnotherAnimal"
})
public class Animals implements Equals2, ToString2
{
@XmlElements({
@XmlElement(name = "dog", type = Dog.class),
@XmlElement(name = "cat", type = Cat.class),
@XmlElement(name = "anotherAnimal", type = AnotherAnimal.class)
})
protected List<Object> dogOrCatOrAnotherAnimal;
...
}
So, each list of <animals> can contain an unbounded list of dogs, cats, and other animals.
So, my problem is in this List<Object> dogOrCatOrAnotherAnimal.
Because it has List of Objects instead of Map of typed classes.
But the main problem is, this class uses for XML <> JSON conversions and I am able to marshal such object to JSON easily, but cannot unmarshal back to the XML string due to the wrong List structure.
I need either a Map of typed objects or any possible solution how to solve this problem.
And one more problem, is here any changes entirely into the XSD schema are forbidden.
I seemed stuck with the generation of Java classes by XSD. When we have a few XSD elements placed on the same level which to be converted to Java Object, the JAXB generates a
List<Object>
. This issue violates thePOJO > XML
unmarshaling.I have an XML message, it looks like:
Here is an XSD schema to generate Java classes:
The generated class looks like:
So, each list of
<animals>
can contain an unbounded list of dogs, cats, and other animals.So, my problem is in this
List<Object> dogOrCatOrAnotherAnimal
. Because it has List of Objects instead of Map of typed classes.But the main problem is, this class uses for
XML <> JSON
conversions and I am able to marshal such object to JSON easily, but cannot unmarshal back to the XML string due to the wrong List structure.I need either a Map of typed objects or any possible solution how to solve this problem. And one more problem, is here any changes entirely into the XSD schema are forbidden.
What could be the best way to fix this problem?