[kotlin-client][multiplatform] add support for kotlinx.datetime.LocalTime (#19590)

This commit is contained in:
Csaba Kozák
2024-09-16 17:10:32 +02:00
committed by GitHub
parent 3832cb4eb7
commit 1b30c1995f
10 changed files with 134 additions and 17 deletions

View File

@@ -27,6 +27,7 @@ src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt
src/main/kotlin/org/openapitools/client/infrastructure/InstantAdapter.kt
src/main/kotlin/org/openapitools/client/infrastructure/LocalDateAdapter.kt
src/main/kotlin/org/openapitools/client/infrastructure/LocalDateTimeAdapter.kt
src/main/kotlin/org/openapitools/client/infrastructure/LocalTimeAdapter.kt
src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt
src/main/kotlin/org/openapitools/client/infrastructure/PartConfig.kt
src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt

View File

@@ -2,18 +2,17 @@ package org.openapitools.client.infrastructure
import com.squareup.moshi.FromJson
import com.squareup.moshi.ToJson
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import kotlinx.datetime.LocalDate
class LocalDateAdapter {
@ToJson
fun toJson(value: LocalDate): String {
return DateTimeFormatter.ISO_LOCAL_DATE.format(value)
return value.toString()
}
@FromJson
fun fromJson(value: String): LocalDate {
return LocalDate.parse(value, DateTimeFormatter.ISO_LOCAL_DATE)
return LocalDate.parse(value)
}
}

View File

@@ -2,18 +2,17 @@ package org.openapitools.client.infrastructure
import com.squareup.moshi.FromJson
import com.squareup.moshi.ToJson
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import kotlinx.datetime.LocalDateTime
class LocalDateTimeAdapter {
@ToJson
fun toJson(value: LocalDateTime): String {
return DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(value)
return value.toString()
}
@FromJson
fun fromJson(value: String): LocalDateTime {
return LocalDateTime.parse(value, DateTimeFormatter.ISO_LOCAL_DATE_TIME)
return LocalDateTime.parse(value)
}
}

View File

@@ -0,0 +1,18 @@
package org.openapitools.client.infrastructure
import com.squareup.moshi.FromJson
import com.squareup.moshi.ToJson
import kotlinx.datetime.LocalTime
class LocalTimeAdapter {
@ToJson
fun toJson(value: LocalTime): String {
return value.toString()
}
@FromJson
fun fromJson(value: String): LocalTime {
return LocalTime.parse(value)
}
}

View File

@@ -8,6 +8,7 @@ object Serializer {
val moshiBuilder: Moshi.Builder = Moshi.Builder()
.add(OffsetDateTimeAdapter())
.add(InstantAdapter())
.add(LocalTimeAdapter())
.add(LocalDateTimeAdapter())
.add(LocalDateAdapter())
.add(UUIDAdapter())