给定以下注释
@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 提供一个适配器。
@XmlJavaTypeAdapter(ThirdAdapter.class)
public class Third implements Dimension
但是,ThirdAdapter 似乎从未被调用过。 @XmlJavaTypeAdapter 与@XmlElements 兼容吗?或者有更好的解决方案吗?
最佳答案
注意:我是 EclipseLink JAXB (MOXy) JAXB (JSR-222) 的领导和成员专家组。
这似乎是 JAXB 中的错误 reference implementation .它也是一个 bug在 EclipseLink JAXB (MOXy) ,但我们已在 EclipseLink 2.4.0 流中修复它。您可以从以下位置下载候选版本:
jaxb.properties
要将 MOXy 用作您的 JAXB 提供程序,您需要在与您的域模型相同的包中添加一个名为 jaxb.properties
的文件,其中包含以下条目:
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
关于annotations - jaxb,我可以将@XmlJavaTypeAdapter 与@XmlElements 一起使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11105338/