-
Notifications
You must be signed in to change notification settings - Fork 0
/
TransientFinalExample.java
executable file
·38 lines (31 loc) · 1.16 KB
/
TransientFinalExample.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
///usr/bin/env jbang "$0" "$@" ; exit $?
//RUNTIME_OPTIONS -ea
//DEPS org.projectlombok:lombok:LATEST
//DEPS com.flowlogix:flowlogix-jee:LATEST
import java.io.*;
import com.flowlogix.util.*;
import lombok.*;
import lombok.extern.java.*;
@Log
@Builder(toBuilder = true)
public class TransientFinalExample implements Serializable {
static class NonSerializableField {
final Integer intValue;
public NonSerializableField(Integer intValue) {
this.intValue = intValue;
}
}
final Integer intValue = 5;
final transient NonSerializableField nonSerializableField = new NonSerializableField(6);
Object readResolve() {
// return new TransientFinalExample();
return toBuilder().build();
}
public static void main(String... args) throws IOException, ClassNotFoundException {
log.info("Checking Serialization ...");
var original = new TransientFinalExample();
TransientFinalExample deserialized = SerializeTester.serializeAndDeserialize(original);
assert original.nonSerializableField.intValue.equals(deserialized.nonSerializableField.intValue);
log.info("Done");
}
}