Wednesday, October 31, 2007

Generate is property set methods in JAXB objects

Keywords:
JAXB "is property set" method object

Problem:
Defining a default value in the schema does not come through as a default value in the generated objects. This could be worked around if you could check for when a field has been explicitly set in the XML (as opposed the value being returned by the get or is) method being the default).

Solution:
Along the lines of past post - Getting xs:any as DOM object

You simply add another custom binding property:
<xs:appinfo>
    <jaxb:property generateIsSetMethod="true"/>
</xs:appinfo> 

This post has the snippet: How do you pick up default values from XSD/JAXB
Reasonable summary of Customizing JAXB Bindings (though not that easy to read): Customizing JAXB Bindings.

No comments: