JAXB Avoid saving default values

后端 未结 2 853
余生分开走
余生分开走 2021-01-13 05:01

Is there any way to make JAXB not save fields which values are the default values specified in the @Element annotations, and then make set the value to it when loading eleme

2条回答
  •  暖寄归人
    2021-01-13 05:44

    For a programmatic solution, there's also good old Apache commons XmlSchema and you can check against the default value with XmlSchemaElement.getDefaultValue()

    So with something like

    XmlSchemaElement elem = schema.getElementByName(ELEMENT_QNAME);
    String defval = elem.getDefaultValue();
    

    you should be able to do what you need. Haven't tried it out in the end, because I needed a more direct solution, but I hope that helps.

提交回复
热议问题