Category Archives: Java

JAXB 2.1 Generating Primitive Type Getters

We’ve been using JAXB generated classes at work for quite some time without problem. Recently it became necessary to make them serializable so we could stow certain objects safely in the HttpSession for later retrieval. So a quick look around on the web revealed the following example in the Sun docs showing how to use xjc’s extension mechanism to force generated classes to implement Serializable. All good. Except as it turns out the Sun docs included the generateIsSetMethod attribute on the <jaxb:globalBindings> element: <jaxb:globalBindings generateIsSetMethod="true">. Originally I included this attribute in my external bindings file that I passed to XJC, thinking I should follow the Sun example, but it soon became clear that this wasn’t the way to go: when I swapped the newly generated classes with our previous version a colleague spotted some of our code complaining about primitive types being returned from the Getters in the generated classes.
Continue reading JAXB 2.1 Generating Primitive Type Getters