开发者

What xml schema context is generated the method signature like "JAXBElemet<Xyz> createXyz(Xyz xyz)" of ObjectFactory by xjc?

I noticed the the simpleType or complexType is defined and the types are used in the dec开发者_JAVA技巧larations of multiple element in a schema file, the simpleType or complexType is generated a method signature as "JAXBElemet createXyz(Xyz xyz)". But I'm not sure if it is root reason.


In order to marshal an object to XML, JAXB needs to know the name of the XML element to be used. It gets this either from (a) the @XmlRootElement annotation on the class, or (b) by wrapping the object in a JAXBElement, which contains the element name.

If XJC generates a class without @XmlRootElement, then the factory methods for that class in ObjectFactory will instead use JAXBElement wrappers, to provide the required marshalling information.

You may then ask why XJC decides to generate @XmlRootElement for some classes but not others, but that's been asked on SO before, so go and have a look around for that one.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜