Skip to content

Commit

Permalink
add kotlinx serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
isXander committed Dec 27, 2021
1 parent 25a7f2c commit 34f629a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
plugins {
kotlin("jvm") version "1.6.0"
kotlin("plugin.serialization") version "1.6.0"
`java-library`
`maven-publish`
}

group = "org.bundleproject"
version = "0.0.2"
version = "0.0.3"

repositories {
mavenCentral()
}

dependencies {
api(kotlin("stdlib-jdk8", "1.6.0"))
api("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.1")
}

tasks {
Expand Down
20 changes: 20 additions & 0 deletions src/main/kotlin/org/bundleproject/libversion/Serializer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.bundleproject.libversion

import kotlinx.serialization.KSerializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

class Serializer : KSerializer<Version> {
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("version", PrimitiveKind.STRING)

override fun deserialize(decoder: Decoder): Version {
return Version.of(decoder.decodeString())
}

override fun serialize(encoder: Encoder, value: Version) {
encoder.encodeString(value.toString())
}
}
3 changes: 3 additions & 0 deletions src/main/kotlin/org/bundleproject/libversion/Version.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.bundleproject.libversion

import kotlinx.serialization.Serializable

@Serializable(Serializer::class)
class Version(
val major: Int,
val minor: Int = 0,
Expand Down

0 comments on commit 34f629a

Please sign in to comment.