I have an issue serializing and unserializing ReportTO using jaxb.
The problem is at the ReportletConf list:
public List<ReportletConf> getReportletConfs() {
return reportletConfs;
}
As ReportletConf is an interface JAXB can not handle it. So we get an
IllegalAnnotationException or similar and JAXB does not even initialize.
So I introduced the annotation below. This allowed the serialization to run.
@XmlElement(type=AbstractReportletConf.class)
The problem now is that the result of the serialization is not complete
and can not be deserialized into the actual classes.
This is how it looks (in an example I did with simplified classes:
<?xml version="1.0" encoding="UTF-8"
standalone="yes"?><report><reportletConfs><name>test</name><description>desc</description></reportletConfs></report>
As you can see there is not enough information to detect the real class.
So I tried to change the signature to use the abstract class and not use
the annotation:
public List<AbstractReportletConf> getReportletConfs()
This works:
<?xml version="1.0" encoding="UTF-8"
standalone="yes"?><report><reportletConfs
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="staticReportletConf"><name>test</name><description>desc</description></reportletConfs></report>
>From the xsi:type jaxb knows the class to instantiate.
So there are the following questions:
- Is there a better way to achieve correct serialization of interfaces ?
- Would it be ok if I change ReportletTO to use the abstract class?
- I would like to avoid the xsi:type and instead have elements for each
class extending AbstractReportletConf. Is that possible?
Best regards
Christian
--
Christian Schneider
http://www.liquid-reality.de
Open Source Architect
http://www.talend.com