Introducing Java Serialized Objects

I am looking for a format that Java uses to serialize objects. Serialization, by default, serializes the object in binary format. In particular, I am curious to know if two runs of a program can serialize the same object in different ways.

What condition must an object satisfy in order for the object to support its behavior as part of the default serialization / deserialization of Java round-trip?

+6
java serialization deterministic
source share
7 answers

I like the @Stephen C example of Object.hashCode (). If such non-deterministic hash codes are serialized, then when we deserialize, the hash codes will be useless. For example, if we serialize a HashMap that works based on Object.hashCode (), its deserialized version will behave differently from the original map. That is, a search for the same object will give us different results on two maps.

0
source share

You need a specification for serializing Java objects in http://java.sun.com/javase/6/docs/platform/serialization/spec/protocol.html .

+10
source share

If you have two objects with all properties set to the same value, they will be serialized the same way.

If he did not repeat, then it would be useless!

+2
source share

They will always serialize it in the same way. If this were not so, there would be no guarantee that another program could correctly serialize the data, surpassing the goal of serialization.

+1
source share

Typically, running the same single-threaded algorithm with the same data will produce the same result.

However, things like the order in which HashSet strings are serialized are not guaranteed. In fact, an object can be subtly resized during serialization.

+1
source share
0
source share

I am looking for a format that Java uses to serialize objects.

In order not to be crazy, he somehow writes. How exactly this is possible and probably should be determined by you. The symbol displays ... well, it takes part, but instead of reinventing the wheel, let us ask what exactly do you need to restore the object in what state?

Serialization is the default serialization object in binary format.

So? (again, not trying to be stupid - it sounds like we need to identify a problem that may not have clear data)

I am interested to know if two runs of a program can serialize the same object in different ways.

If you have a flow of information, how would you determine in which states the object should be restored?

-2
source share

All Articles