### Registering Typed IDs Annotation Processor with Gradle Source: https://github.com/framefork/typed-ids/blob/master/README.md Configures the Gradle build script to include the `typed-ids-index-java-classes-processor` as an annotation processor for both main and test source sets. This enables compile-time indexing of typed ID subtypes. ```Kotlin dependencies { annotationProcessor("org.framefork:typed-ids-index-java-classes-processor") testAnnotationProcessor("org.framefork:typed-ids-index-java-classes-processor") } ``` -------------------------------- ### Registering Typed IDs Annotation Processor with KAPT (Kotlin) Source: https://github.com/framefork/typed-ids/blob/master/README.md Configures the Kotlin build script to include the `typed-ids-index-java-classes-processor` using the KAPT plugin. This is the required method for running Java annotation processors in Kotlin projects. ```Kotlin dependencies { kapt("org.framefork:typed-ids-index-java-classes-processor") // instead of annotationProcessor(...) } ``` -------------------------------- ### Configuring Kotlin Serialization Json with Contextual Typed ID Module Source: https://github.com/framefork/typed-ids/blob/master/README.md Configures a Kotlin Serialization `Json` instance by providing a `serializersModule` obtained from the `ObjectUuidKotlinxSerializationModule.fromIndex`. This module uses the compile-time index to automatically register serializers for typed IDs. ```Kotlin val json = Json { serializersModule = ObjectUuidKotlinxSerializationModule.fromIndex } ``` -------------------------------- ### Registering Typed IDs Annotation Processor with Maven (Optional) Source: https://github.com/framefork/typed-ids/blob/master/README.md Adds the `typed-ids-index-java-classes-processor` as an optional dependency in the Maven `pom.xml`. This relies on Maven's automatic annotation processor discovery. ```XML org.framefork typed-ids-index-java-classes-processor true ``` -------------------------------- ### Explicitly Registering Typed IDs Annotation Processor with Maven Compiler Plugin Source: https://github.com/framefork/typed-ids/blob/master/README.md Configures the Maven Compiler Plugin to explicitly include the `typed-ids-index-java-classes-processor` in the annotation processor path. This ensures the processor runs reliably during compilation. ```XML org.apache.maven.plugins maven-compiler-plugin org.framefork typed-ids-index-java-classes-processor ``` -------------------------------- ### Implementing ObjectBigIntId Wrapper in Java Source: https://github.com/framefork/typed-ids/blob/master/README.md Provides the standard Java boilerplate for creating a type-safe ID class (`User.Id`) that extends `ObjectBigIntId` to wrap a native `long`. It includes factory methods for generating random `long` IDs and creating IDs from string or `long` values, demonstrating how to instantiate the typed ID. ```java public record User(Id id) { public static final class Id extends ObjectBigIntId { private Id(final long inner) { super(inner); } public static Id random() { return ObjectBigIntId.randomBigInt(Id::new); } public static Id from(final String value) { return ObjectBigIntId.fromString(Id::new, value); } public static Id from(final long value) { return ObjectBigIntId.fromLong(Id::new, value); } } } // ... var user = new User(Id.random()); ``` -------------------------------- ### Implementing ObjectUuid Wrapper in Java Source: https://github.com/framefork/typed-ids/blob/master/README.md Provides the standard Java boilerplate for creating a type-safe ID class (`User.Id`) that extends `ObjectUuid` to wrap a native `UUID`. It includes factory methods for generating random UUIDv7 IDs and creating IDs from string or UUID values, demonstrating how to instantiate the typed ID. ```java public record User(Id id) { public static final class Id extends ObjectUuid { private Id(final UUID inner) { super(inner); } public static Id random() { return ObjectUuid.randomUUID(Id::new); } public static Id from(final String value) { return ObjectUuid.fromString(Id::new, value); } public static Id from(final UUID value) { return ObjectUuid.fromUuid(Id::new, value); } } } // ... var user = new User(Id.random()); ``` -------------------------------- ### Implementing ObjectUuid Wrapper in Kotlin Source: https://github.com/framefork/typed-ids/blob/master/README.md Shows the standard Kotlin boilerplate for creating a type-safe ID class (`User.Id`) that extends `ObjectUuid` to wrap a native `UUID`. It uses a companion object to provide factory methods for generating random UUIDv7 IDs and creating IDs from string or UUID values. ```kotlin data class User(id: Id) { class Id private constructor(id: UUID) : ObjectUuid(id) { companion object { fun random() = randomUUID(::Id) fun from(value: String) = fromString(::Id, value) fun from(value: UUID) = fromUuid(::Id, value) } } } ``` -------------------------------- ### Implementing ObjectBigIntId Wrapper in Kotlin Source: https://github.com/framefork/typed-ids/blob/master/README.md Shows the standard Kotlin boilerplate for creating a type-safe ID class (`User.Id`) that extends `ObjectBigIntId` to wrap a native `long`. It uses a companion object to provide factory methods for generating random `long` IDs and creating IDs from string or `long` values. ```kotlin data class User(id: Id) { class Id private constructor(id: UUID) : ObjectBigIntId(id) { companion object { fun random() = randomBigInt(::Id) fun from(value: String) = fromString(::Id, value) fun from(value: Long) = fromLong(::Id, value) } } } ``` -------------------------------- ### Using Explicitly Serializable Typed ID in Kotlin Data Class Source: https://github.com/framefork/typed-ids/blob/master/README.md Shows how to use a custom `UserId` type, which has an explicit Kotlin Serialization serializer defined, within a standard `@Serializable` data class. No extra annotations are needed on the usage site. ```Kotlin @Serializable data class UserDto(val id: UserId) ``` -------------------------------- ### Defining Kotlin Serializable Typed ID with Explicit Serializer Source: https://github.com/framefork/typed-ids/blob/master/README.md Defines a custom `UserId` class extending `ObjectUuid` and marks it as `@Serializable` with an explicit `Serializer` object. This provides a dedicated serialization mechanism for the specific ID type. ```Kotlin @Serializable(with = UserId.Serializer::class) class UserId private constructor(id: UUID) : ObjectUuid(id) { // standard boilerplate ... object Serializer : ObjectUuidSerializer(::UserId) } ``` -------------------------------- ### Mapping Typed ID with Hibernate ORM using @Type Annotation (Pre-Indexing) Source: https://github.com/framefork/typed-ids/blob/master/README.md Demonstrates how to map a custom `ObjectUuid` typed ID field in a Hibernate ORM entity using the `@Type` annotation. This explicit mapping is required when automatic type registration via indexing is not used. ```Java @Entity public class User { @jakarta.persistence.Id @Column(nullable = false) @Type(ObjectUuidType.class) private Id id; // ... public static final class Id extends ObjectUuid { // ... } } ``` -------------------------------- ### Using Contextual Typed ID in Kotlin Data Class Source: https://github.com/framefork/typed-ids/blob/master/README.md Shows how to use a custom `UserId` type within a `@Serializable` data class when using the contextual serialization module. The `@Contextual` annotation is required on the field to indicate that its serializer should be looked up from the configured module. ```Kotlin @Serializable data class UserDto(@Contextual val id: UserId) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.