Class SerializationExamples
java.lang.Object
net.jrodolfo.java_evolution.java01.serialization.SerializationExamples
Demonstrates object serialization, introduced in Java 1.1.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSmall serializable object graph used by the examples.static classNested serializable object reached from the root snapshot. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondeserialize(byte[] bytes) Deserializes bytes produced by this example.Serializes and deserializes the object once.byte[]Serializes a trusted in-memory object to bytes.
-
Constructor Details
-
SerializationExamples
public SerializationExamples()
-
-
Method Details
-
serialize
Serializes a trusted in-memory object to bytes.- Parameters:
snapshot- object to serialize- Returns:
- serialized object bytes
- Throws:
IOException- when the object cannot be written
-
deserialize
public SerializationExamples.ProjectSnapshot deserialize(byte[] bytes) throws IOException, ClassNotFoundException Deserializes bytes produced by this example.- Parameters:
bytes- trusted serialized object bytes- Returns:
- deserialized project snapshot
- Throws:
IOException- when the bytes cannot be readClassNotFoundException- when the serialized class is unavailable
-
roundTrip
public SerializationExamples.ProjectSnapshot roundTrip(SerializationExamples.ProjectSnapshot snapshot) throws IOException, ClassNotFoundException Serializes and deserializes the object once.- Parameters:
snapshot- object to round-trip- Returns:
- reconstructed object
- Throws:
IOException- when serialization failsClassNotFoundException- when deserialization cannot load the class
-