users@jaxb.java.net

Re: Unmarshalling in a custom way

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Wed, 7 Nov 2007 15:21:04 +0100

Hi.

> I have an XML file that I'd like to unmarshall to Java based on
> JAXB-annotated classes. I'd like to be able to do this in a custom way,
> however - right now every attribute gets unmarshalled as a String. Is there
> a way to provide a custom attribute-unmarshaller or something that says to
> JAXB if an attribute is of type Class, for example, then use this custom
> converter class of mine to convert it from the String value in the XML to a
> Class object?
>
> I could of course have a set of data access objects in JAXB with only
> Strings then domain objects that do the conversion, but it seems overkill
> and a maintenance headache to have two parallel object hierarchies just
> because I can't customize the way JAXB unmarshalls.
>
> Is this possible with JAXB, or am I out of luck? Any suggestions?

I'm not sure what exactly your problem is, but:

* Simply declare properties fields in the appropriate type if it is
known to JAXB.
* Use XMLAdapter to provide custom conversion.

Bye.
/lexi