jaxb,我可以将@XmlJavaTypeAdapter 与@XmlElements 一起使用吗? [英] jaxb, can I use @XmlJavaTypeAdapter with @XmlElements?

查看:44
本文介绍了jaxb,我可以将@XmlJavaTypeAdapter 与@XmlElements 一起使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定以下注释

@XmlElements({
 @XmlElement(name = "first", type = First.class),
 @XmlElement(name = "second", type = Second.class),
 @XmlElement(name = "third", type = Third.class),
 @XmlElement(name = "fourth", type = Fourth.class),
 @XmlElement(name = "fifth", type = Fifth.class),
 @XmlElement(name = "sixth", type = Sixth.class),
 @XmlElement(name = "seventh", type = Seventh.class)})
private List<Dimension> dimensions = new ArrayList<>();

由于一些有趣的遗留逻辑,我需要为 Third.class 提供一个适配器.

And because of some funny legacy logic, I need to provide an adapter for Third.class.

@XmlJavaTypeAdapter(ThirdAdapter.class)
public class Third implements Dimension

然而,ThirdAdapter 似乎从未被调用过.@XmlJavaTypeAdapter 与 @XmlElements 兼容吗?或者有更好的解决方案吗?

However, ThirdAdapter never seems to be called. Is @XmlJavaTypeAdapter compatible with @XmlElements? Or is there a better solution to this?

推荐答案

注意:我是EclipseLink JAXB (MOXy) 领导和成员 JAXB (JSR-222) 专家组.

Note: I'm the EclipseLink JAXB (MOXy) lead and a member of the JAXB (JSR-222) expert group.

这似乎是 JAXB 参考实现中的一个错误.这也是 bugEclipseLink JAXB (MOXy),但我们已在 EclipseLink 2.4 中修复它.0 流.您可以从以下位置下载候选版本:

This appears to be a bug in the JAXB reference implementation. It was also a bug in EclipseLink JAXB (MOXy), but we have fixed it in our EclipseLink 2.4.0 stream. You can download a release candidate from the following location:

jaxb.properties

要将 MOXy 用作您的 JAXB 提供程序,您需要在与域模型相同的包中添加一个名为 jaxb.properties 的文件,其中包含以下条目:

To use MOXy as your JAXB provider you need to add a file called jaxb.properties in the same package as your domain model with the following entry:

javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory

这篇关于jaxb,我可以将@XmlJavaTypeAdapter 与@XmlElements 一起使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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