Tôi đã đưa ra giải pháp phần nào đủ. Trong ứng dụng của tôi, chỉ PersistentSets đã làm rối tung XML được tạo ra bởi XStream. Vì vậy, tôi đã thêm một Converter để XStream (mà chạy với mở Hibernate Session và đối tượng trực tiếp):
XStream xs = new XStream();
xs.registerConverter(new CollectionConverter(xs.getMapper()) {
@Override
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
org.hibernate.collection.PersistentSet ps = (PersistentSet) source;
super.marshal(new HashSet(ps), writer, context);
}
@Override
public boolean canConvert(Class type) {
return type.isAssignableFrom(org.hibernate.collection.PersistentSet.class);
}
}, XStream.PRIORITY_VERY_HIGH);
String s = xs.toXML(processInstance);
XML serialized trông giống như dưới đây:
<processLogs class="org.hibernate.collection.PersistentSet">
<pl.net.bluesoft.rnd.processtool.model.ProcessInstanceLog>
<id>813017</id>
<entryDate>
<time>1310832421216</time>
<timezone>GMT</timezone>
</entryDate>
<eventI18NKey>process.log.action-performed</eventI18NKey>
<additionalInfo>Wydrukuj wniosek</additionalInfo>
<logValue>GENERATE_APPLICATION</logValue>
<logType>PERFORM_ACTION</logType>
<state reference="../../../definition/states/pl.net.bluesoft.rnd.processtool.model.config.ProcessStateConfiguration[8]"/>
<processInstance reference="../../.."/>
<user reference="../../../creator"/>
</pl.net.bluesoft.rnd.processtool.model.ProcessInstanceLog>
<pl.net.bluesoft.rnd.processtool.model.ProcessInstanceLog>
<id>808211</id>
<entryDate>
<time>1310828206169</time>
<timezone>GMT</timezone>
</entryDate>
<eventI18NKey>process.log.action-performed</eventI18NKey>
<additionalInfo>Zaakceptuj</additionalInfo>
<logValue>ACCEPT</logValue>
<logType>PERFORM_ACTION</logType>
<state reference="../../../definition/states/pl.net.bluesoft.rnd.processtool.model.config.ProcessStateConfiguration[4]"/>
<processInstance reference="../../.."/>
<user reference="../../../creator"/>
</pl.net.bluesoft.rnd.processtool.model.ProcessInstanceLog>
Trong trường hợp của tôi, các thuộc tính lớp không quan trọng, vì vậy tôi đã bỏ qua giá trị của nó. Bạn có thể tinker với nó.
Nguồn
2011-07-16 18:25:26
Có thể bạn có thể hiển thị XML trông như thế nào? –