- Type Parameters:
T- the record type this instantiator constructs.
The metamodel generators emit an implementation per record type that invokes the record's canonical
constructor (the primary constructor for Kotlin data classes) directly, registered through
META-INF/services/st.orm.mapping.Instantiator. The row mapper dispatches to a registered instantiator
instead of Constructor.newInstance, so applications run without reflective construction: no reflection
configuration for native images, and no opens clauses for modular applications.
When no instantiator is registered for a type, the row mapper falls back to reflective construction, so models compiled without the generators keep working unchanged.
- Since:
- 1.13
-
Method Summary
Modifier and TypeMethodDescriptiondefault @Nullable Object @Nullable []deconstruct(T instance) Deconstructs the given instance into its canonical constructor arguments, in declaration order.instantiate(@Nullable Object[] args) Constructs a new instance from the canonical constructor arguments.type()Returns the record type this instantiator constructs.
-
Method Details
-
type
Returns the record type this instantiator constructs.- Returns:
- the constructed record type.
-
instantiate
Constructs a new instance from the canonical constructor arguments.The arguments are positional and fully adapted: the caller has already performed null checks and type conversion, so implementations only cast and invoke the constructor.
- Parameters:
args- the canonical constructor arguments, in declaration order; elements arenullwhere the corresponding component is.- Returns:
- the constructed instance.
-
deconstruct
Deconstructs the given instance into its canonical constructor arguments, in declaration order.Generated instantiators override this to read the components directly, completing the reflection-free round trip for record rebuilds: component reads run as generated code, matching
instantiate(java.lang.Object[])on the construction side. The returned array is freshly allocated; callers may modify it and pass it toinstantiate(java.lang.Object[])to build an adjusted copy of the instance.The default returns
null, signalling that no generated deconstructor is available; callers fall back to reflective component access.- Parameters:
instance- the instance to deconstruct.- Returns:
- the component values in declaration order, or
nullwhen not supported. - Since:
- 1.13
-