Skip to content

Commit 0e90e43

Browse files
feat: add zero's proxy class
Co-Authored-By: Zero_DSRS_VX <24632178+PhoenixVX@users.noreply.github.com>
1 parent c3952e1 commit 0e90e43

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package me.dexrn.jos.common.test;
2+
3+
import java.io.InvalidObjectException;
4+
import java.io.ObjectInputStream;
5+
import java.io.Serial;
6+
import java.io.Serializable;
7+
8+
public class JOSProxyClass implements Serializable {
9+
private int myFunnyInt = 69420;
10+
11+
@Serial
12+
private void readObject(ObjectInputStream stream) throws InvalidObjectException {
13+
throw new InvalidObjectException("Proxy required.");
14+
}
15+
16+
17+
@Serial
18+
private Object writeReplace() {
19+
return new SerializationProxy(this);
20+
}
21+
22+
public static class SerializationProxy implements Serializable {
23+
@Serial
24+
private static final long serialVersionUID = 0L;
25+
26+
private final int myProxiedFunnyInt;
27+
28+
public SerializationProxy(JOSProxyClass josProxyClass) {
29+
this.myProxiedFunnyInt = josProxyClass.myFunnyInt;
30+
}
31+
32+
33+
@Serial
34+
private Object readResolve() {
35+
JOSProxyClass jos = new JOSProxyClass();
36+
jos.myFunnyInt = this.myProxiedFunnyInt;
37+
return jos;
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)