MOXy mapping question [message #389791] |
Mon, 06 July 2009 11:51  |
Eclipse User |
|
|
|
Hi!
I'm having a bit of trouble mapping an object to XML using MOXy.
My object looks something like this:
public class DesignationRequest {
private String numericId;
private String alphanumericId;
// Getters and setters.
}
The thing is only one of the Ids should be set be set and the other should
be null. What's more is that each of the Ids come in two different
"flavours", meaning the XML can be one of these four variations:
<app:DesignationRequest>
<app:numericId>
<value>625</value>
</app:numericId>
</app:DesignationRequest>
or
<app:DesignationRequest>
<app:numericIdTypeB>
<value>625</value>
</app:numericIdTypeB>
</app:DesignationRequest>
or
<app:DesignationRequest>
<app:alphanumericId>
<value>62e</value>
</app:alphanumericId>
</app:DesignationRequest>
or
<app:DesignationRequest>
<app:alphanumericIdTypeB>
<value>62e</value>
</app:alphanumericIdTypeB>
</app:DesignationRequest>
The XSD ought to look something like the following, though I can't quite
seem to get the namespaces right:
<xs:element name="DesignationRequest">
<xs:complexType>
<xs:sequence>
<xs:choice>
<xs:element name="numericId" type="value"/>
<xs:element name="numericIdTypeB" type="value"/>
<xs:element name="alphanumericId" type="value"/>
<xs:element name="alphanumericIdTypeB" type="value"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="value">
<xs:sequence>
<xs:element name="value" type="xs:string"/>
</xs:sequence>
</xs:complexType>
Anyway, I have no idea how to do the MOXy mapping. Is
XMLChoiceObjectMapping the way to go, or can I use XMLDirectMapping
somehow? I've tried choice mapping by using
descriptor.addChoiceElement("app:numericId/value", String.class);
though this gives an error that the String class is not defined or
something something of the sort. Any help would be appreciated.
/Matti
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04263 seconds