If I encode a class with java.beans.XMLEncoder (Java 1.6) like the following:
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).
Is there any guarantee on the ordering of fields of an object that is encoded by XMLEncoder
?
If not, how can I enforce an ordering which is the same each time an object is xml-encoded?
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. It seems that the implementation of XMLEncoder
differs for the IBM and Sun JVM.