Skip Headers

# Mappings and JAXB Typesafe Enumerations

Previous

Next

JAXB binds a typesafe enumeration class to a named simple type definition with a `basetype` that derives from `xsd:NCName` and has `enumeration` facets (see Example: Schema Fragment with Typesafe Enumeration Declaration).

Schema Fragment with Typesafe Enumeration Declaration

    <simpleType name="NISTSchema-NCName-enumeration-1-Type">
        <restriction base="NCName">
            <enumeration value="qbandwidth-and.software-use.too"/>
            <enumeration value="_effort-disseminate_and-devices.com"/>
        </restriction>
    </simpleType>

You can map a Java attribute to such an enumeration using the `JAXBTypesafeEnumConverter` with an `EISDirectMapping` or `EISCompositeDirectCollectionMapping` with XML records or with an `XMLDirectMapping` or `XMLCompositeDirectCollectionMapping` with XML documents.

TopLink Workbench does not support the `JAXBTypesafeEnumConverter` directly: to configure a mapping with this converter, you must use a descriptor amendment method (see "Configuring a JAXB Typesafe Enumeration Converter").

If you create a project and object model using the TopLink JAXB compiler (see "Creating an XML Project From an XML Schema"), the compiler will create the type safe enumeration class and a class with descriptor amendment methods and register the required amendment methods automatically (see "Typesafe Enumeration Converter Amendment Method DescriptorAfterLoads Class").