JAXB需要一个公共的无参数构造函数? [英] What JAXB needs a public no-arg constructor for?
问题描述
在编组期间,JAXB需要一个公共的无参数构造函数?
What does JAXB need a public no-arg constructor for, during marshalling?
Marshaller msh = ctx.createMarshaller();
msh.marshal(object, System.out);
我正在传递一个对象,而不是一个类。为什么JAXB需要构造函数?构造什么?
I'm passing an object, not a class. Why does JAXB need a constructor? To construct what?
推荐答案
在编组操作期间,JAXB实现不需要no-arg构造函数。 JAXB确实需要一个用于解组。通常,在创建JAXBContext时,缺少no-arg构造函数会导致错误。您正在使用的JAXB实现可能会延迟初始化,直到执行实际操作。
A JAXB implementation should not need a no-arg constructor during a marshal operation. JAXB does require one for unmarshalling. Normally the absence of a no-arg constructor causes an error when the JAXBContext is created. The JAXB implementation you are using may be delaying initialization until an actual operation is performed.
对于多arg构造函数的一般支持是我们在将来的版本中应该考虑的事情。 JAXB。在 JAXB(MOXy)的EclipseLink实现中,我们为此功能打开了一个增强请求(随意添加相关内容)详情):
In general support for multi-arg constructors is something we should consider in a future version of JAXB. In the EclipseLink implementation of JAXB (MOXy) we have an enhancement request open for this functionality (feel free to add relevant details):
- https://bugs.eclipse.org/328951.
在当前版本的JAXB中,您可以使用XmlAdapter来支持这个用例:
In the current version of JAXB you could use an XmlAdapter to support this use case:
- http://bdoughan.blogspot.com/2010/07/xmladapter-jaxbs-secret-weapon.html
这篇关于JAXB需要一个公共的无参数构造函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!