Is there any way to combine 2 Java properties to a single XML element using
annotations or binding language?
Here is a simple example of what I'd like to do:
<complexType name="PhoneType">
<sequence>
<element name="number" type="xs:string"/>
</sequence>
</complexType>
public class Phone {
String area;
String localNumber;
}
I'd like to be able to marshall Phone to PhoneType with an expression like:
"(" + area " ")" + " " + localNumber
The only way that I can see to do this is to modify Phone, so that it is like
this:
@XmlAccessorType(AccessType.NONE)
public class Phone {
String area;
String localNumber;
@XmlElement
public String getNumber() {
return "(" + area " ")" + " " + localNumber;
}
public void setNumber(String number) {
area = ... // some parse thingy
localNumber = ... // some other parse thingy
}
}
So, it seems like the only way to do this is to add the setter/getters
corresponding to the XML element. 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.
Any ideas/comments would be much appreciated.
-- Mark