users@jaxb.java.net

Re: splitting/combining properties

From: Kohsuke Kawaguchi <kohsuke.kawaguchi_at_sun.com>
Date: Thu, 12 Jan 2006 09:46:17 +0900

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) {...}
}

-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com