mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-11 10:32:42 +00:00
[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())
|
||||
|
||||
@@ -32,7 +32,7 @@ data class Order (
|
||||
@Json(name = "quantity")
|
||||
val quantity: kotlin.Int? = null,
|
||||
@Json(name = "shipDate")
|
||||
val shipDate: java.time.LocalDateTime? = null,
|
||||
val shipDate: java.time.OffsetDateTime? = null,
|
||||
/* Order Status */
|
||||
@Json(name = "status")
|
||||
val status: Order.Status? = null,
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.openapitools.client.apis.PetApi
|
||||
import org.openapitools.client.apis.StoreApi
|
||||
import org.openapitools.client.models.Order
|
||||
import org.openapitools.client.models.Pet
|
||||
import java.time.LocalDateTime.now
|
||||
import java.time.OffsetDateTime.now
|
||||
|
||||
class StoreApiTest : ShouldSpec() {
|
||||
init {
|
||||
|
||||
Reference in New Issue
Block a user