generated from Kantis/kotlin-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding serializers for OffsetDateTime and LocalTime
- Loading branch information
Showing
4 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
ks3-jdk/src/jvmMain/kotlin/io/ks3/java/time/LocalTimeAsStringSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.ks3.java.time | ||
|
||
import io.ks3.standard.stringSerializer | ||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.Serializable | ||
import java.time.LocalTime | ||
|
||
typealias LocalTimeAsString = @Serializable(with = LocalTimeAsStringSerializer::class) LocalTime | ||
|
||
object LocalTimeAsStringSerializer : KSerializer<LocalTime> by stringSerializer( | ||
LocalTimeAsStringSerializer::class.qualifiedName!!, | ||
LocalTime::parse, | ||
LocalTime::toString, | ||
) |
14 changes: 14 additions & 0 deletions
14
ks3-jdk/src/jvmMain/kotlin/io/ks3/java/time/OffsetDateTimeAsStringSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.ks3.java.time | ||
|
||
import io.ks3.standard.stringSerializer | ||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.Serializable | ||
import java.time.OffsetDateTime | ||
|
||
typealias OffsetDateTimeAsString = @Serializable(with = OffsetDateTimeAsStringSerializer::class) OffsetDateTime | ||
|
||
object OffsetDateTimeAsStringSerializer : KSerializer<OffsetDateTime> by stringSerializer( | ||
OffsetDateTimeAsStringSerializer::class.qualifiedName!!, | ||
OffsetDateTime::parse, | ||
OffsetDateTime::toString, | ||
) |
12 changes: 12 additions & 0 deletions
12
ks3-jdk/src/jvmTest/kotlin/io/ks3/java/time/LocalTimeAsStringSerializerTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.ks3.java.time | ||
|
||
import io.kotest.core.spec.style.FreeSpec | ||
import io.kotest.property.Arb | ||
import io.kotest.property.arbitrary.localTime | ||
import io.ks3.test.generateSerializerTests | ||
|
||
class LocalTimeAsStringSerializerTests: FreeSpec( | ||
{ | ||
include(generateSerializerTests(LocalTimeAsStringSerializer, Arb.localTime())) | ||
} | ||
) |
12 changes: 12 additions & 0 deletions
12
ks3-jdk/src/jvmTest/kotlin/io/ks3/java/time/OffsetDateTimeAsStringSerializerTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.ks3.java.time | ||
|
||
import io.kotest.core.spec.style.FreeSpec | ||
import io.kotest.property.Arb | ||
import io.kotest.property.arbitrary.localTime | ||
import io.ks3.test.generateSerializerTests | ||
|
||
class OffsetDateTimeAsStringSerializerTests: FreeSpec( | ||
{ | ||
include(generateSerializerTests(LocalTimeAsStringSerializer, Arb.localTime())) | ||
} | ||
) |