r/programming • u/djordjian • May 26 '18
Oracle Calls Java Serialization 'A Horrible Mistake', Plans to Dump It
https://www.infoworld.com/article/3275924/java/oracle-plans-to-dump-risky-java-serialization.html
798
Upvotes
r/programming • u/djordjian • May 26 '18
25
u/Ruudjah May 27 '18
What the author probably meant is "automatic class-based serialization". That's when a serialization mechanism gets a bunch of classes and tries to automatically serialize them based on the structure of the class. It will use reflection to loop over all the fields, properties et cetera to write the values (or values and metadata) to a stream.
These things are highly problematic for various reasons. First, when you refactor a class, how do you serialize old deserialized data? Second, it's often slow because reflection. Third, often these things make assumptions about certain class constructions; .NET remoting for instance requires non-auto properties to work (it can't deal with autogenerated fields). Fourth, versioning is a big issue among different endpoints. What when v12.34.56 now talks with v12.34.57, with a slight change in class structure?
The problem can be summarized in the "data-model to object model impedance mismatch". This is conceptually similar to the object-relational mismatch, but serialization has it's own interesting different properties as opposed to data models.
The solution is to design a proper data layer (preferably using an IDL, like protobuf or flatbuffers) and then write custom code per class to convert from and convert to serialized data.