【发布时间】:2017-11-16 09:31:55
【问题描述】:
假设我有以下 POJO 类,我想使用 JAXB 编组
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
Class Employee {
private String firstName;
private String lastName;
private int age;
}
现在我正在使用以下代码 sn-p 编组 Employee 类的实例
JAXBContext jc = JAXBContext.newInstance(Employee.class);
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
OutputStream os = new FileOutputStream("C:\\employee.xml")
marshaller.marshal(employee, os);
生成的 XML 看起来像
<Employee>
<firstName>Mark</firstName>
<lastName>Smith</lastName>
<age>30</age>
</Employee>
问题:我不希望员工数据周围有默认的员工标签。 即
我想要输出如下
<firstName>Mark</firstName>
<lastName>Smith</lastName>
<age>30</age>
如何做到这一点?
【问题讨论】:
标签: java xml jaxb marshalling