[BAEL-3524] A Guide to @Serial Annotation in Java 14 (#8433)

* BAEL-1935: Synthetic Class in Java

* Converted tabs to spaces

* [BAEL-3524] Created project core-java-14 with @Serial demo.
This commit is contained in:
Donato Rimenti
2020-01-01 17:38:39 +01:00
committed by KevinGilmore
parent c34bf5b28a
commit d9dc2d8159
2 changed files with 102 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
package com.baeldung.serial;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamException;
import java.io.ObjectStreamField;
import java.io.Serial;
import java.io.Serializable;
/**
* Class showcasing the usage of the Java 14 @Serial annotation.
*
* @author Donato Rimenti
*/
public class MySerialClass implements Serializable {
@Serial
private static final ObjectStreamField[] serialPersistentFields = null;
@Serial
private static final long serialVersionUID = 1;
@Serial
private void writeObject(ObjectOutputStream stream) throws IOException {
// ...
}
@Serial
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
// ...
}
@Serial
private void readObjectNoData() throws ObjectStreamException {
// ...
}
@Serial
private Object writeReplace() throws ObjectStreamException {
// ...
return null;
}
@Serial
private Object readResolve() throws ObjectStreamException {
// ...
return null;
}
}