public final class RuntimeSerialization extends Object
Modifier and Type | Method and Description |
---|---|
static void |
register(Class<?>... classes)
Makes the provided classes available for serialization at runtime.
|
static void |
registerIncludingAssociatedClasses(Class<?> clazz)
Register the specified serialization target class itself and all associated classes.
|
static void |
registerLambdaCapturingClass(Class<?> lambdaCapturingClass)
Makes a class available for serialization at runtime that is created for the lambda
expressions (a class that has a $deserializeLambda$ method) specified by the
lambdaCapturingClass.
|
static void |
registerProxyClass(Class<?>... implementedInterfaces)
Makes a dynamic proxy class (class that extends
Proxy ) available
for serialization at runtime that is specified by the given interfaces the proxy class
implements. |
static void |
registerWithTargetConstructorClass(Class<?> clazz,
Class<?> customTargetConstructorClazz)
Makes the provided class available for serialization at runtime but uses the provided
customTargetConstructorClazz for deserialization.
|
public static void registerIncludingAssociatedClasses(Class<?> clazz)
According to the Java Object Serialization Specification, the associated classes include 1) all the target class' non-static and non-transient fields types and their associated classes; 2) other fields defined in the customised writeObject(ObjectOutputStream) and readObject(ObjectInputStream). This method can automatically explore all possible serialization target classes in the first scenario, but can't figure out the classes in the second scenario.
Another limitation is the specified clazz
must have no subclasses (effectively
final). Otherwise, the actual serialization target class could be any subclass of the
specified class at runtime.
clazz
- the serialization target classpublic static void register(Class<?>... classes)
public static void registerWithTargetConstructorClass(Class<?> clazz, Class<?> customTargetConstructorClazz)
In some cases an application might explicitly make calls to
ReflectionFactory.newConstructorForSerialization(Class<?> cl, Constructor<?> constructorToCall)
where the passed `constructorToCall` differs from what would automatically be used if regular
deserialization of `cl` would happen. This method exists to also support such usecases.
public static void registerLambdaCapturingClass(Class<?> lambdaCapturingClass)