toOwnerIdGetterIfAnnotated

Creates a property getter for the owner ID if the property is annotated with @OwnerId.

This method scans the property for the @OwnerId annotation and, if present, converts the property to a string getter for accessing the owner identifier.

Example usage:

class UserOwnedCommand(
@OwnerId
val userId: String
)

val command = UserOwnedCommand("user-789")
val ownerGetter = UserOwnedCommand::userId.toOwnerIdGetterIfAnnotated()
val ownerId = ownerGetter?.get(command) // Returns "user-789"

Return

a PropertyGetter for the owner ID, or null if the property is not annotated

Parameters

T

the type of the object containing the property

See also

Throws

if the annotated property is not of type String