I have the following elements in my mapping file:

          <p:class name="domain.Authentication">
            <p:map-to xml="authentication"/>
            <p:field name="status">
              <p:bind-xml name="status" node="attribute" />
            </p:field>
          </p:class>
          
          <p:class name="domain.DataResult">
            <p:map-to xml="DataResult"/>
            <p:field name="returnValue">
              <p:bind-xml name="ReturnValue" node="element" />
            </p:field>
            <p:field name="textOutput">
              <p:bind-xml name="TextOutput" node="element" />
            </p:field>
            <p:field name="status">
              <p:bind-xml name="status" node="attribute"/>
            </p:field>
          </p:class>

I try to unmarshall the following xml

        <authentication status="false" />

Using the following unmarshalling works as expected (creates a valid
Authentication object)

        Unmarshaller unm = new Unmarshaller(Authentication.class);
        unm.setMapping(mMapping);
        ClassPathResource resource = new
ClassPathResource("data/authentication.xml");
        InputStreamReader reader = new
InputStreamReader(resource.getInputStream());
        Authentication result = (Authentication)unm.unmarshal(reader);

The following unmarshalling works, but not the way I exected - it creates a
DataResult object with the status attribute set to false.

        Unmarshaller unm = new Unmarshaller(DataResult.class);
        unm.setMapping(mMapping);
        ClassPathResource resource = new
ClassPathResource("data/authentication.xml");
        InputStreamReader reader = new
InputStreamReader(resource.getInputStream());
        DataResult result = (DataResult)unm.unmarshal(reader);

I would have expected that the <p:map-to xml="DataResult"/> tag would have
caused a MarshallException as the <authentication> tag is obviously not a
<DataResult> tag.

If anybody can help me get Castor to check against the map-to attribute
during unmarshalling I would greatly appreciate that.

Thanks,
Niels
_______________
Niels K. Kirkegaard - Senior Software Engineer
Insightful Corp. - 1700 Westlake Ave N, Suite 500, Seattle, WA, 98109, USA
Email: [EMAIL PROTECTED]
Phone: +1 206 802 2256  -  Fax: +1 206 283 8691

Reply via email to