Question

I'm looking to update our project's jaxb version from 1 to 2. Has anyone tried doing this on their projects and are there any tips that anyone wanting to do this? I understand that each project is unique, I'm just looking for general tips.

Was it helpful?

Solution

JAXB2 will generate enum classes for simpletype restrictions. Any Java code which relies on setting string values for uses of these types will require you to use the appropriate enum instead. I think this is great, since you get the typechecking when compiling rather than a validation warning at runtime.

JABX2 uses typed lists instead of untyped lists, so you can remove a lot of casting from your java code.

Date support is greatly improved. IIRC, most of the date types in JAXB1 generate Calendar, whereas in JAXB2 they generate XMLGregorianCalendar.

OTHER TIPS

Today I was reading a tutorial on JAXB 1, and tried compiling the example using JAXB 2.1 (as included in JavaSE 6). The elements in the XSD used unnamed types, such as:

<xs:element name="logging">
        <xs:complexType>
                <xs:attribute name="debug" type="xs:boolean" use="required"/>
                <xs:attribute name="file" type="xs:string" use="required"/>
        </xs:complexType>
</xs:element>

For what I see, JAXB 1.0 generated a Logging class and a LoggingType class (referring to the unnamed type of the logging element), while JAXB 2 generates just a Logging class. This happens regularly on all tags of this example, so I guess this happens quite regularly in such cases. However, it sufficed to remove the "Type" suffix to fix the compilation, without any need for other changes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top