forked from loafle/openapi-generator-original
[kotlin][client] Use OffsetDateTime to represente date-time received by the server (#4835)
* [kotlin] add OffsetDateTime support * [kotlin] serializer add missing import * [kotlin] update pet projects and fix tests * [kotlin] update docs * [kotlin] update pet projects * [kotlin] update date-time * [kotlin] update pet project * [kotlin] update windows script
This commit is contained in:
committed by
William Cheng
parent
ad6c832162
commit
3eaafce569
@@ -0,0 +1,19 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import com.squareup.moshi.FromJson
|
||||
import com.squareup.moshi.ToJson
|
||||
import java.time.OffsetDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
class OffsetDateTimeAdapter {
|
||||
@ToJson
|
||||
fun toJson(value: OffsetDateTime): String {
|
||||
return DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(value)
|
||||
}
|
||||
|
||||
@FromJson
|
||||
fun fromJson(value: String): OffsetDateTime {
|
||||
return OffsetDateTime.parse(value, DateTimeFormatter.ISO_OFFSET_DATE_TIME)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,6 +9,7 @@ object Serializer {
|
||||
@JvmStatic
|
||||
val moshiBuilder: Moshi.Builder = Moshi.Builder()
|
||||
.add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe())
|
||||
.add(OffsetDateTimeAdapter())
|
||||
.add(LocalDateTimeAdapter())
|
||||
.add(LocalDateAdapter())
|
||||
.add(UUIDAdapter())
|
||||
|
||||
Reference in New Issue
Block a user