Hi,

Consider the following XML document:
<emp>
<name>John Doe</name>
<empId>03700</empId>
<role>
<dept>IT</dept>
<title>mgr</title>
</role>
<phone>123456</phone>
</emp>
It is easy to unmarshal this document to the class Employee with a field of "type" Set containing a single Role-instance:
class Employee{
private String name;
private String empId;
private String phone;
private Set roles; // set of one or more Role's
...
}
class Role{
private String dept;
private String title;
}
Once in a while, the external application which provides the XML-data also provides data for an employee with two roles with the second role appended at the end of the document:
<emp>
<name>John Doe</name>
<empId>03700</empId>
<role>
<dept>IT</dept>
<title>mgr</title>
</role>
<phone>123456</phone>
<role>
<dept>Finance</dept>
<title>mgr</title>
</role>
</emp>
In this case, JiBX fails to unmarshal because it expects a </emp>-tag after the </phone>-tag (and not the second <role>-tag).  Apparently, JiBX  unmarshalling only works for elements appearing in the order they are defined in the binding.  When I put the second <role>-element directly behind the first <role>-element, everything works fine.  Is this behaviour expected?

Or am I somewhere wrong?

Anybody has encountered the same problem?  An easy way to fix this?  As the information comes from an external party, it would not be easy to have them change the layout of XML messages.

I am using JiBX 1.0.1 and I use a binding in the style of:
<binding>
    <mapping name="emp"
        class="Employee">
        <value name="name" field="name" />
        <value name="empId" field="empId" />   
        <value name="phone" field="phone" />
        <collection field="roles"
            factory="Factory.listFactory"
            item-type="Role"
            usage="optional"/>
    </mapping>
    <mapping name="roles" class="Role">
        <value name="dept" field="dept" />
        <value name="title" field="title" />
    </mapping>
</binding>


regards,
Bruno.

Reply via email to