Skip to content

manosbatsis/kmp-converters

Repository files navigation

Kotlin Multiplatform Converters Maven Central

Playground for support of common KMP types in popular JVM frameworks or APIs, like JPA, Spring Boot, Elide and SQLDelight.

This repo is experimental and largely untested. Use at your own risk. Contributions welcome.

Supported KMP libraries:

Gradle Setup

Releases are available from Maven Central. Snapshots are available from Sonatype's OSS repository:

// For snapshots, optional
maven("https://oss.sonatype.org/content/repositories/snapshots/")

For Plain JPA

The following Gradle dependency adds JPA Attribute Converters for supported KMP types:

implementation("com.github.manosbatsis.kmp.converters:kmp-converters-jpa:$kmpConvertersVersion")

The converters can be found in the com.github.manosbatsis.kmp.converters.jpa package.

JPA Identifiers

Note that JPA does not apply Attribute Converters on @Id annotated members. If you need to use one of the supported KMP types as an identifier, you can work around the JPA spec limitation in three steps:

  1. Wrap the converted type within an Embeddable type
  2. Use the wrapper as the id type
  3. Annotate the id @EmbeddedId

For example, suppose you want to use com.benasher44.uuid.Uuid as an identifier:

@Embeddable
class UuidId {
    @Column(name = "ID", nullable = false)
    @Convert(converter = UuidAttributeConverter::class)
    private var id: Uuid? = null
}

// In your entity
@Entity
class MyEntity(
    @EmbeddedId
    private var pk: UuidId? = null
)

For Spring Boot

The following starter configures the JPA Attribute Converters described above:

implementation("com.github.manosbatsis.kmp.converters:kmp-converters-springboot-starter:$kmpConvertersVersion")

For Elide Standalone

The following dependencies add JPA Attribute Converters (as described above) and Serde implementations for supported KMP types:

implementation("com.github.manosbatsis.kmp.converters:kmp-converters-jpa:$kmpConvertersVersion")
implementation("com.github.manosbatsis.kmp.converters:kmp-converters-elide:$kmpConvertersVersion")

For Elide with Spring Boot

The following starter configures both JPA and Serde converters described in previous sections:

implementation("com.github.manosbatsis.kmp.converters:kmp-converters-elide-starter:$kmpConvertersVersion")

For SQLDelight

The following Gradle dependency adds custom column types for supported KMP types:

implementation("com.github.manosbatsis.kmp.converters:kmp-converters-sqldelight:$kmpConvertersVersion")

The converters reside in the com.github.manosbatsis.kmp.converters.sqldelight package.

About

Support common KMP types in JPA, Spring Boot, Elide, SQLDelight...

Topics

Resources

License

Stars

Watchers

Forks

Languages