fyou serialize một đối tượng, bạn phải có các lớp học để deserialize và sử dụng đối tượng. OK, đó là rõ ràng. Nhưng những gì có thể ít rõ ràng hơn là những gì sẽ xảy ra nếu bạn thay đổi classin khi chờ đợi? Yikes. Hãy tưởng tượng đang cố gắng để mang lại một đối tượng Dog khi một trong các biến dụ của nó | saving objects Version IP A Pig Serialization Gotcha Now you ve seen that I o in Java is actually pretty simple especially if you stick to the most common connection chain combinations. But there s one issue you might really care about. Version Control is crucial If you serialize an object you must have the class in order to deserialize and use the object. OK that s obvious. But what might be less obvious is what happens if you change the class in the meantime Yikes. Imagine trying to bring back a Dog object when one of its instance variables non-transient has changed from a double to a String. That violates Java s type-safe sensibilities in a Big Way. But that s not the only change that might hurt compatibility. Think about the following Changes to a class that can hurt deserialization Deleting an instance variable Changing the declared type of an instance variable Changing a non-transient instance variable to transient Moving a class up or down the inheritance hierarchy Changing a class anywhere in the object graph from Serializable to not Serializable by removing implements Serializable from a class declaration Changing an instance variable to static Changes to a class that are usually OK Adding new instance variables to the class existing objects will deserialize with default values for the instance variables they didn t have when they were serialized Adding classes to the inheritance tree Removing classes from the inheritance tree Changing the access level of an instance variable has no affect on the ability of deserialization to assign a value to the variable Changing an instance variable from transient to non-transient previously-serialized objects will simply have a default value for the previously-transient variables You write a bog class L01101 ULrt 101101 Tj WM 0 Mass 010X0 1 v 1010101 . A n 1001010101 IF 1 MB You serialize a bog object using that class You change the bog class 101101 c 101101 101000010 Mass vers 0 1010 10 0 01010 1 100001 1010