From a44039648580774e48ee80c9fb0c26fc5786a7ad Mon Sep 17 00:00:00 2001 From: William Cheng Date: Mon, 18 Feb 2019 22:27:04 +0800 Subject: [PATCH] update kotline samples --- .../openapitools/client/infrastructure/ApiClient.kt | 4 +++- .../client/infrastructure/ByteArrayAdapter.kt | 12 ++++++++++++ .../openapitools/client/infrastructure/ApiClient.kt | 4 +++- .../client/infrastructure/ByteArrayAdapter.kt | 12 ++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt create mode 100644 samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index fa6f15fbd05..9e79028a90b 100644 --- a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -60,7 +60,9 @@ open class ApiClient(val baseUrl: String) { fun toJson(uuid: UUID) = uuid.toString() @FromJson fun fromJson(s: String) = UUID.fromString(s) - }).build().adapter(T::class.java).fromJson(body.source()) + }) + .add(ByteArrayAdapter()) + .build().adapter(T::class.java).fromJson(body.source()) else -> TODO() } } diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt new file mode 100644 index 00000000000..617ac3fe906 --- /dev/null +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt @@ -0,0 +1,12 @@ +package org.openapitools.client.infrastructure + +import com.squareup.moshi.FromJson +import com.squareup.moshi.ToJson + +class ByteArrayAdapter { + @ToJson + fun toJson(data: ByteArray): String = String(data) + + @FromJson + fun fromJson(data: String): ByteArray = data.toByteArray() +} \ No newline at end of file diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index fa6f15fbd05..9e79028a90b 100644 --- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -60,7 +60,9 @@ open class ApiClient(val baseUrl: String) { fun toJson(uuid: UUID) = uuid.toString() @FromJson fun fromJson(s: String) = UUID.fromString(s) - }).build().adapter(T::class.java).fromJson(body.source()) + }) + .add(ByteArrayAdapter()) + .build().adapter(T::class.java).fromJson(body.source()) else -> TODO() } } diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt new file mode 100644 index 00000000000..617ac3fe906 --- /dev/null +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt @@ -0,0 +1,12 @@ +package org.openapitools.client.infrastructure + +import com.squareup.moshi.FromJson +import com.squareup.moshi.ToJson + +class ByteArrayAdapter { + @ToJson + fun toJson(data: ByteArray): String = String(data) + + @FromJson + fun fromJson(data: String): ByteArray = data.toByteArray() +} \ No newline at end of file