jaxb, can I use @XmlJavaTypeAdapter with @XmlElements?

[亡魂溺海] 提交于 2019-12-21 20:25:39

问题


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?


回答1:


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

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

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


来源:https://stackoverflow.com/questions/11105338/jaxb-can-i-use-xmljavatypeadapter-with-xmlelements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!