JAXB marshaller exception - bound to an anonymous type



I'm trying to write a program that can programmatically assemble a FOP document, for generation of a PDF. I know, reinventing the wheel, but I'm just doing it as an excercise.


I've obtained the XSD for FOP from here: http://ift.tt/1v0hUAf


I used that with XJC to generate JAXB objects, and I'm composing a document as follows:



public static void main(String[] args) throws Exception {

JAXBContext jaxbContext = JAXBContext.newInstance(Root.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

Root root = new Root();
LayoutMasterSet layoutMasterSet = new LayoutMasterSet();
SimplePageMaster simplePageMaster = new SimplePageMaster();
simplePageMaster.setMasterName("one");
RegionBody regionBody = new RegionBody();
simplePageMaster.setRegionBody(regionBody);
layoutMasterSet.getSimplePageMasterOrPageSequenceMaster().add( simplePageMaster );

PageSequence pageSequence = new PageSequence();
pageSequence.setMasterReference("one");
Flow flow = new Flow();
flow.setFlowName("xsl-region-body");
pageSequence.setFlow(flow);
layoutMasterSet.getSimplePageMasterOrPageSequenceMaster().add(pageSequence);
root.setLayoutMasterSet( layoutMasterSet );

jaxbMarshaller.marshal(root, System.out);

}


This code works fine until I include the part that adds the PageSequence -

then it throws the following exception:



Exception in thread "main" javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.internal.SAXException2: Instance of "com.company.jaxb.fop.PageSequence" is substituting "java.lang.Object", but "com.company.jaxb.fop.PageSequence" is bound to an anonymous type.]
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:311)
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:236)
at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:95)
at FopTry.main(FopTry.java:43)
Caused by: com.sun.istack.internal.SAXException2: Instance of "com.company.jaxb.fop.PageSequence" is substituting "java.lang.Object", but "com.company.jaxb.fop.PageSequence" is bound to an anonymous type.
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:237)
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:652)


Any ideas what's going wrong?


No comments:

Post a Comment