users@jaxb.java.net

Re: splitting/combining properties

From: Mark Hansen <mark_at_javector.com>
Date: Wed, 11 Jan 2006 21:05:34 -0500

Thanks. I didn't realize that I could apply XmlJavaTypeAdapter to the
entire class. That is what comes from not reading the spec carefully
enough - but it is > 350 pages! ;-)

I like the idea of being able to link @XmlElement annotations into a
class using static methods from another class. That seems like an
elegant solution.

Kohsuke Kawaguchi wrote:

> mark_at_javector.com wrote:
>
>> Is there any way to combine 2 Java properties to a single XML element
>> using
>
>
> <snip />
>
>> I was wondering if there is a way to use
>> XmlAdapter - but since the marshal/unmarshal methods seem to define a
>> one-one
>> mapping between bound type and value type - I don't see any way to
>> use it to do
>> such splitting/combining.
>
>
> You can adapt the whole Phone class.
>
> @XmlJavaTypeAdapter(PhoneAdapter.class)
> public class Phone { ... }
>
> public class PhoneXML {
> String number;
> }
>
> class PhoneAdapter extends XmlAdapter<Phone,PhoneXML> {
> ... do the conversion between Phone and PhoneXML ...
> }
>
>
>>
>> Any ideas/comments would be much appreciated.
>
>
> I don't think any other existing mechanism does it, but if we can talk
> about how we can extend it to work, then perhaps what we can do is to
> allow static methods on another class to be treated:
>
> @XmlTearOff(PhoneTearOff)
> class Phone {
> String area;
> String localNumber;
> }
>
> class PhoneTearOff {
> @XmlElement
> static String getNumber(Phone p) {...}
> static void setNumber(Phone p,String v) {...}
> }
>