users@jaxb.java.net

Re: Setup a custom XmlAdapter rather than generating one

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Tue, 8 Mar 2011 07:51:47 +0100

On 8 March 2011 01:25, <christian-schulte_at_alice.de> wrote:

> Hi,
>
> I would like to write that Adapter1.java class manually, for example
> MimeTypeXmlAdapter. Is it possible to customize XJC in a way to use
> that custom adapter instead of generating one ? For example:
>
> <jaxb:property>
> <jaxb:baseType>
> <jaxb:javaType name="javax.activation.MimeType"
> adapter="package.MimeTypeXmlAdapter"/>
> </jaxb:baseType>
> </jaxb:property>
>
>
You are almost there :-)

The correct form is
<jaxb:javaType name="javax.activation.MimeType"
            printMethod="my.Foo.printMimeType"
            parseMethod="my.Foo.parseMimeType"/>

and you write my.Foo with
static String printMimeTyp( MimeType mt )
static MimeType parseMimeType( String str )

Also, see
http://jaxb.java.net/tutorial/section_5_6_1-Overriding-the-Datatype.html

-W