Class DatatypeConverter

The javaType binding declaration can be used to customize the binding of
an XML schema datatype to a Java datatype. Customizations can involve
writing a parse and print method for parsing and printing lexical
representations of a XML schema datatype respectively. However, writing
parse and print methods requires knowledge of the lexical representations (
XML Schema Part2: Datatypes
specification ) and hence may be difficult to write.

This class makes it easier to write parse and print methods. It defines
static parse and print methods that provide access to a JAXB provider's
implementation of parse and print methods. These methods are invoked by
custom parse and print methods. For example, the binding of xsd:dateTime
to a long can be customized using parse and print methods as follows:

There is a static parse and print method corresponding to each parse and
print method respectively in the DatatypeConverterInterface.

The static methods defined in the class can also be used to specify
a parse or a print method in a javaType binding declaration.

JAXB Providers are required to call the
setDatatypeConverter api at some point before the first marshal or unmarshal
operation (perhaps during the call to JAXBContext.newInstance). This step is
necessary to configure the converter that should be used to perform the
print and parse functionality.

A print method for a XML schema datatype can output any lexical
representation that is valid with respect to the XML schema datatype.
If an error is encountered during conversion, then an IllegalArgumentException,
or a subclass of IllegalArgumentException must be thrown by the method.

Method Detail

setDatatypeConverter

JAXB Providers are required to call this method at some point before
allowing any of the JAXB client marshal or unmarshal operations to
occur. This is necessary to configure the datatype converter that
should be used to perform the print and parse conversions.

Calling this api repeatedly will have no effect - the
DatatypeConverterInterface instance passed into the first invocation is
the one that will be used from then on.

Parameters:

converter - an instance of a class that implements the
DatatypeConverterInterface class - this parameter must not be null.