Class RuntimeSerialization
- Since:
- 21.3
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
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 extendsProxy
) 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.
-
Method Details
-
registerIncludingAssociatedClasses
Register the specified serialization target class itself and all associated classes.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.- Parameters:
clazz
- the serialization target class- Since:
- 21.3
-
register
Makes the provided classes available for serialization at runtime.- Since:
- 21.3
-
registerWithTargetConstructorClass
public static void registerWithTargetConstructorClass(Class<?> clazz, Class<?> customTargetConstructorClazz) Makes the provided class available for serialization at runtime but uses the provided customTargetConstructorClazz for deserialization.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.- Since:
- 21.3
-
registerLambdaCapturingClass
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.- Since:
- 22.3
-
registerProxyClass
Makes a dynamic proxy class (class that extendsProxy
) available for serialization at runtime that is specified by the given interfaces the proxy class implements.- Since:
- 22.3
-