我有一些课程:
class Location {
private Long id;
private String roomTitle;
protected Specialization specialization;
}
public class Specialization {
private Long id;
private boolean archived;
private String title;
}
和xml:
<location id="10">
<roomTitle>string</roomTitle>
<specializationId>10</specializationId>
</location>
我可以将specializationId
编组为Location.specialization.id
吗?
答案 0 :(得分:0)
我不了解jaxb,但SimpleXml可以做到。
首先,我们需要添加一些注释:
Series.cat.catgeories
请注意,public class Location {
private Long id;
private String roomTitle;
@XmlName("specializationId")
protected Specialization specialization;
}
public class Specialization {
@XmlTextNode
private Long id;
private Boolean archived;
private String title;
}
现在是一个布尔类。常规布尔值不能为null。接下来,我们将xml序列化为Location类。
archived
然后我们可以打印值
final SimpleXml simple = new SimpleXml();
final Location l = simple.fromXml(xml, Location.class);
这将打印
System.out.println(l.specialization.id);
SimpleXml位于Maven中心
10