3

Given the following annotations

@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<>();

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

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

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

4

1 回答 1

2

注意: 我是EclipseLink JAXB (MOXy)负责人,也是JAXB (JSR-222)专家组的成员。

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

jaxb.properties

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

javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
于 2012-06-19T20:47:10.630 回答