I cant figure it out how to add an element to List<Serializabe>
conent, which i got from auto generated java classes using JaxB.
For example, i need to add simple string in that list, but when i pass a string
sadrzaj.getContent().add("some string");
it says that
java.lang.ClassCastException: jaxb.from.xsd.Clan$Sadrzaj$Stav cannot be cast to java.lang.String
Here is my code:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"content"
})
public static class Sadrzaj {
@XmlElementRefs({
@XmlElementRef(name = "Tekst", namespace = "http://www.parlament.gov.rs/clan", type = JAXBElement.class),
@XmlElementRef(name = "Stav", namespace = "http://www.parlament.gov.rs/clan", type = JAXBElement.class)
})
@XmlMixed
protected List<Serializable> content;
public List<Serializable> getContent() {
if (content == null) {
content = new ArrayList<Serializable>();
}
return this.content;
}
My XML schema for static class Sadrzaj looks like this:
<complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <choice>
* <element name="Stav" maxOccurs="unbounded">
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="Redni_broj" type="{http://www.w3.org/2001/XMLSchema}long"/>
* <element name="Tekst" type="{http://www.w3.org/2001/XMLSchema}string"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </element>
* <element name="Tekst" type="{http://www.w3.org/2001/XMLSchema}string" maxOccurs="unbounded"/>
* </choice>
* </restriction>
* </complexContent>
* </complexType>