我有以下课程
@XmlRootElement(name = "entity")
public class Entity {
@XmlElementRef
protected AtomLink first;
@XmlElementRef
protected AtomLink second;
public Entity() {
}
public Entity(AtomLink first, AtomLink second) {
this.first = first;
this.second = second;
}
}
这是我的测试代码:
Entity entity = new Entity(new AtomLink("first", "http://test/first"), new AtomLink("second", "http://test/second"));
JAXBContext context;
try {
context = JAXBContextFactory.createContext(new Class[] { Entity.class } , null);
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(entity, System.out);
} catch (JAXBException e) {
e.printStackTrace();
}
MOXy 的输出是错误的,因为缺少第一个链接:
<entity xmlns:atom="http://www.w3.org/2005/Atom">
<atom:link rel="second" href="http://test/second"/>
</entity>
Java JAXB RI 的输出是正确的:
<entity xmlns:atom="http://www.w3.org/2005/Atom">
<atom:link rel="first" href="http://test/first"/>
<atom:link rel="second" href="http://test/second"/>
</entity>
它是 MOXy 中的错误吗?