users@jaxb.java.net

Re: Custom mapping for Maps in JAXB

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Sat, 19 Jun 2010 08:35:02 +0200

Hello Leo,

On 18 June 2010 19:43, Leo Romanoff <romixlev_at_yahoo.com> wrote:
>
> Hi Wolfgang,
>
>> Say, you have a class Cabinet, where your Map should ultimately be a
>> field.
>> For unmarshalling arbitrary content, you'll need another field
>>   Object any
>>as the root of your arbitrary <k>v</k> stuff. (I'm not seriously
> considering
>>of using the Object any to store the Map, too.) You can do the conversions
>>after the document has been unmarshalled. If you are worried about the
> effort
>>for walking the final tree, you might look into
>>javax.xml.bind.Unmarshaller.Listener, method afterUnmarshal, and do it in
>>the callback.
>
> OK. I understand now how to unmarshall.
>
> But what about marshalling?

It's simply the reverse process.

> Should I somehow produce a DOM tree for my map, so that it is used for the
> xsd:any element?

Yes, same as you get by unmarshalling.

> Should I store this DOM tree into the "Object any" element?

Yes.

> When and how should I do it?

Anytime during the composition of your document tree, before you
call marshal to produce the top level XML.

> May be there is something like a special
> listener or beforeUnmarshal callback?
>

There is javax.xml.bind.Marshaller.Listener, with before and after callbacks,
but you might be able to do without this complication.

-W


> Thanks again,
>   Leo
>
> --
> View this message in context: http://old.nabble.com/Custom-mapping-for-Maps-in-JAXB-tp28779221p28928881.html
> Sent from the java.net - jaxb users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>