JiBX 解组 - 是否可以告诉 JiBX 忽略元素的顺序?
有办法解决这个问题吗?
例如,我的 XML:
<group>
<idExt>new group idext</idExt>
<user-id>1</user-id>
<parent-id>2</parent-id>
</group>
解组时,没有错误,但是当我更改顺序时:
<group>
<user-id>1</user-id>
<parent-id>2</parent-id>
<idExt>new group idext</idExt>
</group>
它失败 org.jibx.runtime.JiBXException:预期“group”结束标记,找到“idExt”开始标记(第 4 行,列2)
。
我的解组(实现 Struts2 ContentTypeHandler 接口):
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);
}
}
和绑定:
<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>
那么,JiBX 是否可以忽略标签顺序?
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</user-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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将
ordered="false"
添加到绑定中的映射元素:有关详细信息,请参阅 JiBX 文档。
Add an
ordered="false"
to your mapping element in the binding:For more info, see the documentation for JiBX.