Hello,
I have to unmarshall the following XML document fragment:
<problem>
<question>
<text>What is the meaning of life?</text>
</question>
<answer>
<choicelist type="single">
<choice correct="true">
<text>42</text>
</choice>
<choice>
<text>Don't know.</text>
</choice>
</choicelist>
</answer>
</problem>
The <problem> element is mapped to a Problem class whose instances
contain the available choices in an ArrayList. The corresponding mapping
file likes the following:
<class name="Problem">
<map-to xml="problem"/>
<field name="type" type="string">
<bind-xml name="type" location="answer/choicelist"
node="attribute"/>
</field>
<field name="question" type="string">
<bind-xml name="text" location="question" node="element"/>
</field>
<field name="choiceList" type="Choice" collection="collection">
<bind-xml name="choice"
location="answer/choicelist"
node="element"/> <!-- USING A COMPOUND PATH IN
THE LOCATION ATTRIBUTE HERE RESULTS IN AN EXCEPTION -->
</field>
</class>
Unmarshalling the XML instance results in the following exception:
org.xml.sax.SAXException: unable to add 'choice' to <test> due to the following
exception:
>>>--- Begin Exception ---<<<
java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at
org.exolab.castor.mapping.loader.FieldHandlerImpl.setValue(FieldHandlerImpl.java:530)
at org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:803)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown
Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:555)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:487)
at Unmarshal.main(Unmarshal.java:23)
>>>---- End Exception ----<<<
at org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:836)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown
Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:555)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:487)
at Unmarshal.main(Unmarshal.java:23)
It seems to me that the problem is with the wrapper element <answer>. When I
remove this wrapper element from the XML instance and from the mapping then
the marshalling goes fine. Thus the following mapping fragment does its job:
<field name="choiceList" type="Choice" collection="collection">
<bind-xml name="choice" location="choicelist" node="element"/>
</field>
It seems to me that I can not use a compound path in the location attribute
when the <bind-xml> element is used in a <field> element with a collection
attribute.
Is it a bug? Has someone noticed this behaviour?
Yours sincerely,
Peter
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev