users@jaxb.java.net

Re: Custom mapping for Maps in JAXB

From: Leo Romanoff <romixlev_at_yahoo.com>
Date: Sun, 20 Jun 2010 03:42:27 -0700 (PDT)

Hi Wolfgang,

I've tried out methods proposed by you and everything (marshalling and
unmarshalling) works now!

BTW, as a result of producing the required format for XML, jersey-json based
on the same JAXB annotations produces a proper natural JSON representation
now.

Thanks a lot!

-Leo


Wolfgang Laun-2 wrote:
>
> 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
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>
>

-- 
View this message in context: http://old.nabble.com/Custom-mapping-for-Maps-in-JAXB-tp28779221p28940012.html
Sent from the java.net - jaxb users mailing list archive at Nabble.com.