Class RuntimeSerialization

java.lang.Object
org.graalvm.nativeimage.hosted.RuntimeSerialization

public final class RuntimeSerialization extends Object
This class provides methods that can be called before and during analysis, to register classes for serialization at image runtime.
Since:
21.3
  • Method Details

    • registerIncludingAssociatedClasses

      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 - the serialization target class
      Since:
      21.3
    • register

      public static void register(Class<?>... classes)
      Makes the provided classes available for serialization at runtime.
      Since:
      21.3
    • registerWithTargetConstructorClass

      @Deprecated(since="24.2") public static void registerWithTargetConstructorClass(Class<?> clazz, Class<?> customTargetConstructorClazz)
      Deprecated.
      Use register(Class[]) instead. All possible custom constructors will be registered automatically.
      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

      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
    • registerProxyClass

      public 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.
      Since:
      22.3