Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Java

io.Serializable: practical reference

io.Serializable: practical reference: Serializable is a marker enabling Java object serialization, but it does not promise a stable or safe cross-version format.

Version: Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime

Syntax

java.io.Serializable

Serializable is a marker enabling Java object serialization, but it does not promise a stable or safe cross-version format.

Use Serializable only when Java object-graph serialization is required and both classes and input format are controlled.

Never deserialize untrusted bytes: hooks can execute code. Declare serialVersionUID; transient is neither encryption nor access control.

Cycles and shared references are preserved. A reachable non-Serializable field can cause NotSerializableException unless excluded or custom-written.

The example exercises the documented element in a small deterministic program and compares exact standard output.

Examples

public class Main {
    public static void main(String[] args) throws Exception {
        System.out.println(java.io.Serializable.class.isAssignableFrom(String.class));
    }
}

Result

true

The example exercises the documented element in a small deterministic program and compares exact standard output.

Sources