JAXB 需要一个公共的无参数构造函数来做什么? [英] What JAXB needs a public no-arg constructor for?

查看:19
本文介绍了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):

在当前版本的 JAXB 中,您可以使用 XmlAdapter 来支持此用例:

In the current version of JAXB you could use an XmlAdapter to support this use case:

这篇关于JAXB 需要一个公共的无参数构造函数来做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆