when does JAXB unmarshaller.unmarshal returns a JAXBElement or a MySchemaObject?

后端 未结 5 1068
日久生厌
日久生厌 2020-12-29 20:41

I have two codes, in two different java projects, doing almost the same thing, (unmarshalling the input of a webservice according to an xsd-file).

But in one case I

5条回答
  •  再見小時候
    2020-12-29 21:07

    It depends on the presence of XmlRootElement annotation on the class of your root element.

    If you generate your JAXB classes from an XSD, the following rules are applied:

    • if the type of the root element is an anonymous type -> XmlRootElement annotation is added to the generated class
    • if the type of the root element is a top level type -> XmlRootElement annotation is omitted from the generated class

    For that reason I often choose anonymous types for root elements.

    You can customize the class name of this anonymous type with a customization file. E.g. create a bindings.xjc file like this:

    
        
            
                
             
        
    
    

提交回复
热议问题