On 29/01/2013 13:09, Christian Schneider wrote:
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 ?

I am not an expert at all of JAXB, passing this question.

- Would it be ok if I change ReportletTO to use the abstract class?

Not good, but still acceptable IMHO.

- I would like to avoid the xsi:type and instead have elements for each
class extending AbstractReportletConf. Is that possible?

Same as above; we will have to remember this when we will finally write a wiki page about how to create custom reports via reportlets.

Regards.

--
Francesco Chicchiriccò

ASF Member, Apache Syncope PMC chair, Apache Cocoon PMC Member
http://people.apache.org/~ilgrosso/

Reply via email to