This project solves two things:
- Provides out-of-the-box serializers for a lof of commonly used Java types.
- Provides utilities for more conveniently defining your own serializers by composition.
This is accomplished without any additional footprint (the project only depends on KotlinX serialization itself).
See the contribution guide here.
Ks3 | Kotlin | KotlinX serialization |
---|---|---|
1.0 | 1.9+ | 1.6+ |
Add the dependency. With Gradle:
dependencies {
implementation("io.ks3:ks3-jdk:1.0.0")
}
Maven:
<dependency>
<groupId>io.ks3</groupId>
<artifactId>ks3-jdk-jvm</artifactId>
<version>1.0.0</version>
</dependency>
Note that when using Maven dependencies must specify the multiplatform variant. For example, append
-jvm
to specify the JVM variant ofks3-jdk
.
Now you can start using the provided serializers. There's several possible ways to do this.
- Using contextual serialization
- Passing a serializer manually
- Specifying serializer on a property
- Specifying serializers for a file
- Specifying serializer using a typealias
typealias LocalDateTimeAsString = @Serializable(LocalDateTimeAsStringSerializer::class) LocalDateTime
data class Appointment(
val datetime: LocalDateTimeAsString
)
For details, see the kotlinx.serialization guide
This method is most useful when you want to use different serial formats for the same type, or when you can't configure the serializer itself.
See the details in kotlinx.serialization guide
@Serializable
class ProgrammingLanguage(
val name: String,
@Contextual
val stableReleaseDate: Date
)
private val module = SerializersModule {
contextual(DateAsLongSerializer)
}
val format = Json { serializersModule = module }