问题
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