【发布时间】:2018-05-20 22:35:14
【问题描述】:
我想在使用 jaxb 解组响应(xml 响应)时删除空字段
例如在解组下面的 xml 响应 usimg jaxb 时
客户 [name=null, age=20, id=100]
是否有任何使用 jaxb 省略空字段的方法,我期望在响应下方
客户 [年龄=20,id=100]
还有其他方法可以实现吗?
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class Customer {
String name;
int age;
int id;
public String getName() {
return name;
}
@XmlElement
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
@XmlElement
public void setAge(int age) {
this.age = age;
}
public int getId() {
return id;
}
@XmlAttribute
public void setId(int id) {
this.id = id;
}
}
XML RESPONSE
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<customer id="100">
<age>29</age>
</customer>
【问题讨论】:
标签: java