JAXB,我可以使用@XmlJavaTypeAdapter与@XmlElements? [英] jaxb, can I use @XmlJavaTypeAdapter with @XmlElements?

查看:1444
本文介绍了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似乎永远不会被调用。与@XmlElements @XmlJavaTypeAdapter兼容?还是有更好的解决呢?

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

推荐答案

注意:我是的 的EclipseLink JAXB(莫西) 领导和的 JAXB(JSR-222) 专家小组。

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

这似乎是在JAXB 参考实现的错误。这也是一个错误 在<一个HREF =htt​​p://www.eclipse.org/eclipselink/#moxy相对=nofollow> 的EclipseLink JAXB(莫西) ,但我们已经在我们的EclipseLink 2.4固定它0.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:

  • http://www.eclipse.org/eclipselink/downloads/milestones.php

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天全站免登陆