DynamicallyMappable
Marks a data class, enum class, or value class as a target for dynamic mapping from dynamic_dto type in PostgreSQL.
This annotation provides a bridge between SQL and Kotlin, allowing the framework to identify which Kotlin class should represent a specific "type" stored in a dynamic_dto column or returned from a query.
NOTE: Usage also requires @Serializable annotation!
Key Concepts
Polymorphism: Allows storing different related types in a single database column.
No Database Schema Changes: Unlike PostgreSQL
COMPOSITEtypes,dynamic_dtobacked by DynamicallyMappable doesn't require additionalCREATE TYPEin the database.Type Safety: The framework uses this annotation to safely deserialize JSONB payloads into strongly-typed Kotlin objects.
Usage Example
@Serializable
@DynamicallyMappable("land_grant")
data class LandGrant(val province: String, val areraActa: BigDecimal)
@Serializable
@DynamicallyMappable("military_pension")
data class MilitaryPension(val legionName: String, val annualAmount: BigDecimal)In SQL, this can be constructed as: SELECT dynamic_dto('land_grant', jsonb_build_object('province', 'Gallia', 'arera_acta', 120.5))
Parameters
The unique identifier (key) for this class. It must match the type name used in the database (e.g., in the dynamic_dto(text, jsonb) constructor).