mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-11 08:22:45 +00:00
[kotlin-client][multiplatform] add support for kotlinx.datetime.LocalTime (#19590)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,6 +8,7 @@ object Serializer {
|
||||
val moshiBuilder: Moshi.Builder = Moshi.Builder()
|
||||
.add(OffsetDateTimeAdapter())
|
||||
.add(InstantAdapter())
|
||||
.add(LocalTimeAdapter())
|
||||
.add(LocalDateTimeAdapter())
|
||||
.add(LocalDateAdapter())
|
||||
.add(UUIDAdapter())
|
||||
|
||||
Reference in New Issue
Block a user