Is there a way to get by this?
For example, my XML:
<group>
<idExt>new group idext</idExt>
<user-id>1</user-id>
<parent-id>2</parent-id>
</group>
when unmarshalling, goes without errors, but when I change order:
<group>
<user-id>1</u开发者_如何学Pythonser-id>
<parent-id>2</parent-id>
<idExt>new group idext</idExt>
</group>
it fails org.jibx.runtime.JiBXException: Expected "group" end tag, found "idExt" start tag (line 4, col 2)
.
My unmarshalling (implementing Struts2 ContentTypeHandler interface):
public void toObject(Reader in, Object target) {
try {
IBindingFactory bf = BindingDirectory.getFactory(target.getClass());
IUnmarshallingContext umc = bf.createUnmarshallingContext();
umc.setDocument(in);
// This un-conditional cast is the current way that JibX unmarshalls to an // already instantiated object - YUCK
((IUnmarshallable)target).unmarshal(umc);
} catch (JiBXException e) {
throw new RuntimeException(e);
}
}
And binding:
<binding>
<mapping name="group" class="GroupVO" >
<value name="id" field="id" usage="optional"/>
<value name="idExt" field="idExt" usage="optional"/>
<value name="active" field="active" usage="optional"/>
<value name="created-at" field="dateCre" usage="optional"/>
<value name="updated-at" field="dateChg" usage="optional"/>
<value name="deleted-at" field="dateDel" usage="optional"/>
<value name="user-id" field="userId" usage="optional" />
<value name="parent-id" field="parentId" usage="optional" />
</mapping>
</binding>
So, is possible for JiBX to ignore tag order?
Add an ordered="false"
to your mapping element in the binding:
<binding>
<mapping name="group" class="GroupVO" ordered="false">
<value name="id" field="id" usage="optional"/>
<value name="idExt" field="idExt" usage="optional"/>
<value name="active" field="active" usage="optional"/>
<value name="created-at" field="dateCre" usage="optional"/>
<value name="updated-at" field="dateChg" usage="optional"/>
<value name="deleted-at" field="dateDel" usage="optional"/>
<value name="user-id" field="userId" usage="optional" />
<value name="parent-id" field="parentId" usage="optional" />
</mapping>
</binding>
For more info, see the documentation for JiBX.
精彩评论