java - No @XmlRootElement generated by JAXB -


I am trying to make Java classes from FPML (FINAL PRODUCTS MARKUP LANGUAGE) version 4.5. A ton of code is generated, but I can not use it. Trying to serial a simple document, I get this:

  javax.xml.bind.MarshalException- with link exception: [com.sun.istack.SAXException2: In martial type Incomplete "org.fpml._2008.fpml_4_5.PositionReport" as an element because it is not an @xmlRootElement annotation]  

In fact @ no classes XmlRootElement is annotation, so what can I do wrong? I am pointing xjc (JAXB 2.1) to fpml-main-4-5.xsd, which contains all the types.

Others have been told or indicated earlier, to tie them with those rules, By which JAXB XJC determines whether the @ XmlRootElement annotation should be placed on a generated class, non-trivial ()

@XmlRootElement exists Because the JAXB Runtime requires special information to martial / unmodified any particular object, especially the XML element name and namespace. You can not pass any old object Marshaler just by providing this information @ XmlRootElement .

Annotations are just a feature, however - JAXB does not need it, the option is to use JAXBElement wrapper items, which can be found in the @XmlRootElement Provide similar information in form, but instead of a comment, as an object.

However, JAXBElement is strange for creating objects, because you need to know the XML element name and namespace, which is not usually a business logic.

Thankfully, when XJC creates a class model, it generates a class called "code> ObjectFactory . This is partly for backwards compatibility with JAXB v1, but it is also a place to make way for Jezek factory, which make the JAXBElement wrapper around their own object . It handles the XML name and name space for you, so you do not have to worry about it.

You only need to see the ObjectFactory methods (and for large schemas, hundreds of them can be).


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -