Scrivio Interview library

Serialization

23 questions in 7 subtopics.

Java serialization mechanics

ConceptFoundations6 min read
How does Java serialization work with ObjectOutputStream and ObjectInputStream? What does a class need to be serializable, and how are superclass fields handled?
CodingFoundations6 min read
Show how to customise serialization of a class with private writeObject and readObject methods, for example to validate fields after reading. What must the methods call?
ConceptIntermediate6 min read
What do readResolve and writeReplace do? Explain how they are used for singletons and for the serialization proxy pattern.
LeadershipPrincipal7 min read
Java serialization was added in 1997 for RMI and distributed objects. Explain why it became a long-term burden for the platform and its users, and what principles you take from it when evaluating new platform features.

SerialVersionUID

ConceptFoundations6 min read
What is serialVersionUID, what happens if you do not declare it, and when should you change it?
DebuggingIntermediate8 min read
After a deployment, a cluster with rolling updates sees InvalidClassException: local class incompatible: stream classdesc serialVersionUID = ... in session replication. What happened and how do you prevent it?

Transient fields

ConceptFoundations6 min read
What does transient do? After deserialization, what values do transient fields have, and how do you restore them?
DebuggingIntermediate7 min read
A class holds a transient final ReentrantLock lock = new ReentrantLock(). After deserialization calls fail with NullPointerException. Explain and give two fixes.

Externalizable

ConceptIntermediate7 min read
Compare Externalizable with Serializable plus writeObject. When was Externalizable a good choice, and what are its risks?

Serialization security and filters

ConceptFoundations7 min read
Why is deserializing untrusted data with ObjectInputStream dangerous? Explain what a gadget chain is.
CodingIntermediate7 min read
Configure a deserialization filter so an ObjectInputStream only accepts classes in com.acme.dto, java.lang and java.util, with limits on depth and array size. Show both a pattern filter and the JVM-wide option.
ScenarioIntermediate6 min read
A security scan reports that an internal admin service accepts Java serialized objects over HTTP. What steps do you take, in order?
ScenarioAdvanced7 min read
A security audit finds Java serialization in a cache library, in JMX remote access and in an old RMI admin tool across about 60 services. Plan the remediation programme across teams.
LeadershipAdvanced6 min read
What organisation-wide policy would you set on Java serialization, given that some frameworks, caches and session replication still rely on it?
LeadershipPrincipal6 min read
Java's own architects have called serialization a major source of security vulnerabilities, and the platform has added filters rather than removing it. What lessons do you take for designing extension points and data formats with long lives?
LeadershipPrincipal6 min read
What would a serialization and deserialization security policy look like for a company with hundreds of Java services, many languages and third-party integrations? Describe its main rules and how you would keep it effective over years.

Records and serialization

CodingFoundations6 min read
Given
record Range(int lo, int hi) implements Serializable {
Range {
if (lo > hi) throw new IllegalArgumentException();
}
}
can a crafted serialized stream create a Range with lo greater than hi? Compare with a normal final class with the same check in its constructor.
ConceptIntermediate6 min read
How does serialization of records differ from ordinary classes, and why is it considered safer?

JSON and binary alternatives

ConceptFoundations6 min read
What are the main alternatives to Java serialization for sending data between services, and what are the trade-offs between JSON and a binary format such as Protobuf?
DebuggingIntermediate7 min read
After enabling Jackson default typing (activateDefaultTyping) so a cache can store polymorphic objects, a security review flags it. Why is this risky, and what is the safer setup?
DesignAdvanced6 min read
Your company is choosing a standard format for data stored long-term, such as event archives kept for seven years, that must stay readable by future services. Compare options and set rules.
DesignAdvanced7 min read
Your company publishes events on Kafka consumed by dozens of teams in several languages. Choose a serialization format and compatibility policy, and explain how you would enforce it.
LeadershipPrincipal6 min read
Over twenty years your company has used Java serialization, XML, SOAP, JSON and now Protobuf. What principles should guide the next data format decisions so migrations cost less?