The code refers to the following articles:
- English: Serialization in Java: Serializable, transient, serialVersionUID
- German: Serialisierung in Java: Serializable, transient, serialVersionUID
The examples work on a small order model: the classes Order and Customer and the record OrderItem. Chapters that need a variant of a class – one that is not serializable, has no serialVersionUID, or validates in readObject() – keep it in a package of its own (graph, transients, versioning, inheritance, custom, special, filter).
Every class with a main() method is one chapter of the article and prints the outputs shown there. Run one with java -cp target/classes eu.happycoders.serialization.<ClassName> after mvn compile. The examples that write files write them into the current directory, with the extension .ser.
Intro– writes an order into a file and reads it backCh1Writing–ObjectOutputStream: writing into a byte array, the first bytes of the stream, bufferingCh2Reading–ObjectInputStream: pattern matching on the result, several objects in one stream, buffering, a file that is not a serialization streamCh3ObjectGraph–NotSerializableException, shared references, the same object written twice,reset()andwriteUnshared()Ch4Transient–transientfields after deserialization and howreadObject()restores themCh5Versioning– the computedserialVersionUIDand what happens when a class changes between writing and readingCh5Misdeclaration– a misdeclaredserialVersionUID, for the JFR eventjdk.SerializationMisdeclaration(the command is in the class comment)Ch6Inheritance– a serializable class with a non-serializable superclassCh7Custom– validation inreadObject(),writeObject()for the superclass state,readResolve(), the serialization proxyCh8Special– records, enums (including a renamed constant), lambdas, and inner classesCh9Collections–ArrayListcapacity,List.of(), views such askeySet()andsubList()Ch10Filters– deserialization filters from patterns, the missing!*, and the limitsmaxdepth(against Joshua Bloch’s deserialization bomb) andmaxarrayCh10FilterFactory– a filter factory that applies a filter within aScopedValuescopeCh10GlobalFilter– a JVM-wide filter with-Djdk.serialFilter(the command is in the class comment; add-Djava.util.logging.config.file=serialfilter-logging.propertiesto log rejected classes)Ch11Size– the size of an order withObjectOutputStreamand withDataOutputStream
The class PackageSwitchingObjectInputStream in eu.happycoders.serialization.util reads a stream written by one version of a class with another version of it: the chapters keep both versions side by side, e.g. versioning.explicit.v1.Customer and versioning.explicit.v2.Customer. Serialization compares class names without their package, so this simulates a class that changed between writing and reading.
Stay up-to-date with the latest Java features with this free PDF Cheat Sheet!
- Avoid lengthy research with this concise overview of all Java versions from Java 10 to Java 27.
- Discover the innovative features of each new Java version, summarized on a single page.
- Impress your team with your up-to-date knowledge of the latest Java version.
👉 Download the free Java Versions PDF
(Hier geht's zur deutschen Version → Java-Versionen PDF)
With this free 1-page PDF cheat sheet, you'll always have the 7 most important complexity classes at a glance.
- Always choose the most efficient data structures and thus increase the performance of your applications.
- Be prepared for technical interviews and confidently present your algorithm knowledge.
- Become a sought-after problem solver and be known for systematically tackling complex problems.
👉 Download the free Big O Cheat Sheet
(Hier geht's zur deutschen Version → O-Notation Cheat Sheet)
👉 Want to stay on top of modern Java? Sign up for the HappyCoders newsletter – Modern Java: new versions & features, performance, and JVM insights – once a month.
(Hier geht's zur deutschen Version → HappyCoders-Newsletter deutsch)
🇩🇪 An alle Java-Entwickler:innen, die durch fundierte Kenntnisse über Datenstrukturen besseren Code schreiben wollen
Trage dich jetzt unverbindlich auf die Warteliste von „Mastering Data Structures in Java“ ein, und erhalte das beste Angebot!


