Top Description Constructors Methods
org.graalvm.nativeimage.hosted

public final Class RuntimeSerialization

extends Object
Class Inheritance
Annotations
@Platforms:HOSTED_ONLY
Imports
org.graalvm.nativeimage.ImageSingletons, .Platform, .Platforms, org.graalvm.nativeimage.impl.ConfigurationCondition, .RuntimeSerializationSupport

This class provides methods that can be called before and during analysis, to register classes for serialization at image runtime.
Since
21.3

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static void
register(Class<?>... classes)

Makes the provided classes available for serialization at runtime.

public static void
registerIncludingAssociatedClasses(Class<?>
the serialization target class
clazz
)

Register the specified serialization target class itself and all associated classes.

public 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.

public static void
registerProxyClass(Class<?>... implementedInterfaces)

Makes a dynamic proxy class (class that extends java.lang.reflect.Proxy) available for serialization at runtime that is specified by the given interfaces the proxy class implements.

public static void
registerWithTargetConstructorClass(Class<?> clazz, Class<?> customTargetConstructorClazz)

Makes the provided class available for serialization at runtime but uses the provided customTargetConstructorClazz for deserialization.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

RuntimeSerializationback to summary
private RuntimeSerialization()

Method Detail

registerback to summary
public static void register(Class<?>... classes)

Makes the provided classes available for serialization at runtime.

Since
21.3
registerIncludingAssociatedClassesback to summary
public static void registerIncludingAssociatedClasses(Class<?> clazz)

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:Class<?>

the serialization target class

Since
21.3
registerLambdaCapturingClassback to summary
public 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.

Since
22.3
registerProxyClassback to summary
public static void registerProxyClass(Class<?>... implementedInterfaces)

Makes a dynamic proxy class (class that extends java.lang.reflect.Proxy) available for serialization at runtime that is specified by the given interfaces the proxy class implements.

Since
22.3
registerWithTargetConstructorClassback to summary
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