有没有办法让JAXB不保存那些值与@Element注释中指定的默认值相同的字段,然后在从XML加载为空或空白元素时设置值?例如:
class Example
{
@XmlElement(defaultValue="default1")
String prop1;
}
Example example = new Example();
example.setProp1("default1");
jaxbMarshaller.marshal(example, aFile);
应该生成:
<example/>
当加载时
Example example = (Example) jaxbUnMarshaller.unmarshal(aFile);
assertTrue(example.getProp1().equals("default1"));
我正在尝试这样做是为了生成一个干净的XML配置文件,使其更易读且文件大小更小。
谢谢您的帮助。