What JAXB needs a public no-arg constructor for?(JAXB 需要一个公共的无参数构造函数来做什么?)
问题描述
在编组期间,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 实现不应该需要无参数构造函数.JAXB 确实需要一个用于解组.通常,在创建 JAXBContext 时,缺少无参数构造函数会导致错误.您使用的 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.
一般来说,我们应该在 JAXB 的未来版本中考虑对多参数构造函数的支持.在 EclipseLink 的 JAXB (MOXy) 实现中,我们对此功能开放了一个增强请求(请随意添加相关的详情):
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 需要一个公共的无参数构造函数来做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:JAXB 需要一个公共的无参数构造函数来做什么?


基础教程推荐
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 降序排序:Java Map 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01