Using Apache Commons 3 to serialize a Set (doesn't seem to matter as using Object streams also leads to same problem):
HashSet<String> hashSet = new HashSet<>();
byte[] serialized = SerializationUtils.serialize(hashSet);
HashSet<String> deserialized = SerializationUtils.deserialize(serialized);
// OK, works
assertEquals(hashSet, deserialized);
byte[] serializedAfterDeserializing = SerializationUtils.serialize(deserialized);
// Nope, different!
assertArrayEquals(serialized, serializedAfterDeserializing);
Anyone has any idea why at the byte level they are not the same?
Doesn't matter if the HashSet has any element or not, even being empty it's not the same.
Using ArrayList the last assert works.