我遇到了jaxb的问题。我需要解决这个问题:
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public abstract class Component implements Serializable {
@XmlID
@XmlAttribute
protected String uuid;
@XmlElements({ @XmlElement(type = ComponentO.class), @XmlElement(type = ComponentI.class),
@XmlElement(type = ComponentIO.class) })
@XmlElementWrapper(name = "childs")
protected List<Component> components = new ArrayList<>();
}
public interface IInputOutput extends IInput, IOutput {
}
@XmlRootElement
public class ComponentIO extends Component implements IInputOutput {
}
@XmlRootElement
public class ComponentI extends Component implements IInput {
}
此解决方案创建了这种xml:
<componentIO uuid="d911479d-597f-4908-ab67-29ee5df5e367">
<name>a</name>
<childs>
<components uuid="9af14b4d-c11c-47fe-9fb9-307da83e30f8">
<name>b</name>
<childs/>
</components>
<components uuid="8a06954c-8e59-4e5b-af9c-c53a103f2f79">
<name>c</name>
<childs>
<components uuid="9af14b4d-c11c-47fe-9fb9-307da83e30f8">
<name>b</name>
<childs/>
</components>
</childs>
</components>
</childs>
</componentIO>
但是,我想要这个:
<componentIO uuid="d911479d-597f-4908-ab67-29ee5df5e367">
<name>a</name>
<childs>
<components uuid="9af14b4d-c11c-47fe-9fb9-307da83e30f8">
<name>b</name>
<childs/>
</components>
<components uuid="8a06954c-8e59-4e5b-af9c-c53a103f2f79">
<name>c</name>
<childs>
<components reference="9af14b4d-c11c-47fe-9fb9-307da83e30f8"/>
</childs>
</components>
</childs>
</componentIO>
当然,当我解组xml文件时,我想要一个组件“b”的实例。
我不知道,我测试使用适配器没有成功......有人有想法吗?
这是第一个问题,如果我们解决这个问题......另一个问题来自^^
谢谢:)