Java Reference
In-Depth Information
Customizing How a Java Class Is Generated from
Schema
Problem
You don't want to accept the default manner in which JAXB generates your Java source and
need to customize the behavior.
Solution
Define a Schemalet file, and add it to the "includes" attribute of the "schema" element in
your XJC Ant task. Alternatively, add JAXB-specific annotations inline to your XML schema.
JAXB does a very good job at the difficult task of mapping schema to Java sources. Schema
element names map to type names, namespaces map to packages, and enumerations map dir-
ectly to Java enumerations. But there are times when you want to override the default be-
havior and specify your own mapping. Perhaps you want to use a different date type than
XMLGregorianCalendar , which is what JAXB generates for an xs:dateTime schema type.
This recipe shows you how to do this.
Table 2-3 shows the default mappings from types built-in to XML Schema to Java types.
Search WWH ::




Custom Search