简体   繁体   English

XMLEncoder是否保证编码对象的字段的固定顺序?

[英]Does XMLEncoder guarantee a fixed order on an encoded object's fields?

If I encode a class with java.beans.XMLEncoder (Java 1.6) like the following: 如果我使用java.beans.XMLEncoder (Java 1.6)对类进行编码,如下所示:

fileOutputStream = new FileOutputStream(someFile);
XMLEncoder xmlEncoder = new XMLEncoder(fileOutputStream);

xmlEncoder.writeObject(anyObject);
xmlEncoder.close();

the result that is written to someFile has a different element ordering when I run it on a different physical machine (also with Java 1.6). 当我在不同的物理计算机(也使用Java 1.6)上运行它时,写入someFile的结果具有不同的元素顺序。

Is there any guarantee on the ordering of fields of an object that is encoded by XMLEncoder ? 是否可以保证XMLEncoder编码的对象的字段的XMLEncoder

If not, how can I enforce an ordering which is the same each time an object is xml-encoded? 如果不是,我该如何强制执行每次对xml编码对象相同的排序?

The reason was that on machine A, the program ran on the IBM JVM while on machine B, the program ran on the Sun JVM. 原因是在机器A上,程序在IBM JVM上运行,而在机器B上,程序在Sun JVM上运行。 It seems that the implementation of XMLEncoder differs for the IBM and Sun JVM. 似乎XMLEncoder的实现对于IBM和Sun JVM是不同的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM