[KOTLIN client] fix Moshi (Serializer/Deserializer) duplicated (#3013)

This commit is contained in:
Vincent Devos 2019-05-28 09:15:06 +02:00 committed by William Cheng
parent d1043c910c
commit d748312818
12 changed files with 26 additions and 70 deletions

View File

@ -30,9 +30,11 @@ test {
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
compile "com.squareup.moshi:moshi-kotlin:1.5.0"
compile "com.squareup.moshi:moshi-adapters:1.5.0"
compile "com.squareup.okhttp3:okhttp:3.14.0"
compile "com.squareup.moshi:moshi-kotlin:1.8.0"
compile "com.squareup.moshi:moshi-adapters:1.8.0"
compile "com.squareup.okhttp3:okhttp:3.14.2"
{{#threetenbp}}
compile "org.threeten:threetenbp:1.3.8"
{{/threetenbp}}
testImplementation "io.kotlintest:kotlintest-runner-junit5:3.1.0"
}

View File

@ -1,8 +1,5 @@
package {{packageName}}.infrastructure
import com.squareup.moshi.KotlinJsonAdapterFactory
import com.squareup.moshi.Moshi
import com.squareup.moshi.Rfc3339DateJsonAdapter
import okhttp3.OkHttpClient
import okhttp3.RequestBody
import okhttp3.MediaType
@ -11,7 +8,6 @@ import okhttp3.HttpUrl
import okhttp3.ResponseBody
import okhttp3.Request
import java.io.File
import java.util.Date
open class ApiClient(val baseUrl: String) {
companion object {
@ -62,14 +58,7 @@ open class ApiClient(val baseUrl: String) {
return null
}
return when(mediaType) {
JsonMediaType -> Moshi.Builder()
.add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe())
.add(LocalDateTimeAdapter())
.add(LocalDateAdapter())
.add(UUIDAdapter())
.add(ByteArrayAdapter())
.add(KotlinJsonAdapterFactory())
.build().adapter(T::class.java).fromJson(bodyContent)
JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent)
else -> TODO("responseBody currently only supports JSON body.")
}
}

View File

@ -1,8 +1,8 @@
package {{packageName}}.infrastructure
import com.squareup.moshi.KotlinJsonAdapterFactory
import com.squareup.moshi.Moshi
import com.squareup.moshi.Rfc3339DateJsonAdapter
import com.squareup.moshi.adapters.Rfc3339DateJsonAdapter
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import java.util.Date
object Serializer {

View File

@ -30,9 +30,8 @@ test {
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
compile "com.squareup.moshi:moshi-kotlin:1.5.0"
compile "com.squareup.moshi:moshi-adapters:1.5.0"
compile "com.squareup.okhttp3:okhttp:3.14.0"
compile "org.threeten:threetenbp:1.3.8"
compile "com.squareup.moshi:moshi-kotlin:1.8.0"
compile "com.squareup.moshi:moshi-adapters:1.8.0"
compile "com.squareup.okhttp3:okhttp:3.14.2"
testImplementation "io.kotlintest:kotlintest-runner-junit5:3.1.0"
}

View File

@ -1,8 +1,5 @@
package org.openapitools.client.infrastructure
import com.squareup.moshi.KotlinJsonAdapterFactory
import com.squareup.moshi.Moshi
import com.squareup.moshi.Rfc3339DateJsonAdapter
import okhttp3.OkHttpClient
import okhttp3.RequestBody
import okhttp3.MediaType
@ -11,7 +8,6 @@ import okhttp3.HttpUrl
import okhttp3.ResponseBody
import okhttp3.Request
import java.io.File
import java.util.Date
open class ApiClient(val baseUrl: String) {
companion object {
@ -62,14 +58,7 @@ open class ApiClient(val baseUrl: String) {
return null
}
return when(mediaType) {
JsonMediaType -> Moshi.Builder()
.add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe())
.add(LocalDateTimeAdapter())
.add(LocalDateAdapter())
.add(UUIDAdapter())
.add(ByteArrayAdapter())
.add(KotlinJsonAdapterFactory())
.build().adapter(T::class.java).fromJson(bodyContent)
JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent)
else -> TODO("responseBody currently only supports JSON body.")
}
}

View File

@ -1,8 +1,8 @@
package org.openapitools.client.infrastructure
import com.squareup.moshi.KotlinJsonAdapterFactory
import com.squareup.moshi.Moshi
import com.squareup.moshi.Rfc3339DateJsonAdapter
import com.squareup.moshi.adapters.Rfc3339DateJsonAdapter
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import java.util.Date
object Serializer {

View File

@ -30,9 +30,9 @@ test {
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
compile "com.squareup.moshi:moshi-kotlin:1.5.0"
compile "com.squareup.moshi:moshi-adapters:1.5.0"
compile "com.squareup.okhttp3:okhttp:3.14.0"
compile "com.squareup.moshi:moshi-kotlin:1.8.0"
compile "com.squareup.moshi:moshi-adapters:1.8.0"
compile "com.squareup.okhttp3:okhttp:3.14.2"
compile "org.threeten:threetenbp:1.3.8"
testImplementation "io.kotlintest:kotlintest-runner-junit5:3.1.0"
}

View File

@ -1,8 +1,5 @@
package org.openapitools.client.infrastructure
import com.squareup.moshi.KotlinJsonAdapterFactory
import com.squareup.moshi.Moshi
import com.squareup.moshi.Rfc3339DateJsonAdapter
import okhttp3.OkHttpClient
import okhttp3.RequestBody
import okhttp3.MediaType
@ -11,7 +8,6 @@ import okhttp3.HttpUrl
import okhttp3.ResponseBody
import okhttp3.Request
import java.io.File
import java.util.Date
open class ApiClient(val baseUrl: String) {
companion object {
@ -62,14 +58,7 @@ open class ApiClient(val baseUrl: String) {
return null
}
return when(mediaType) {
JsonMediaType -> Moshi.Builder()
.add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe())
.add(LocalDateTimeAdapter())
.add(LocalDateAdapter())
.add(UUIDAdapter())
.add(ByteArrayAdapter())
.add(KotlinJsonAdapterFactory())
.build().adapter(T::class.java).fromJson(bodyContent)
JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent)
else -> TODO("responseBody currently only supports JSON body.")
}
}

View File

@ -1,8 +1,8 @@
package org.openapitools.client.infrastructure
import com.squareup.moshi.KotlinJsonAdapterFactory
import com.squareup.moshi.Moshi
import com.squareup.moshi.Rfc3339DateJsonAdapter
import com.squareup.moshi.adapters.Rfc3339DateJsonAdapter
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import java.util.Date
object Serializer {

View File

@ -30,9 +30,8 @@ test {
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
compile "com.squareup.moshi:moshi-kotlin:1.5.0"
compile "com.squareup.moshi:moshi-adapters:1.5.0"
compile "com.squareup.okhttp3:okhttp:3.14.0"
compile "org.threeten:threetenbp:1.3.8"
compile "com.squareup.moshi:moshi-kotlin:1.8.0"
compile "com.squareup.moshi:moshi-adapters:1.8.0"
compile "com.squareup.okhttp3:okhttp:3.14.2"
testImplementation "io.kotlintest:kotlintest-runner-junit5:3.1.0"
}

View File

@ -1,8 +1,5 @@
package org.openapitools.client.infrastructure
import com.squareup.moshi.KotlinJsonAdapterFactory
import com.squareup.moshi.Moshi
import com.squareup.moshi.Rfc3339DateJsonAdapter
import okhttp3.OkHttpClient
import okhttp3.RequestBody
import okhttp3.MediaType
@ -11,7 +8,6 @@ import okhttp3.HttpUrl
import okhttp3.ResponseBody
import okhttp3.Request
import java.io.File
import java.util.Date
open class ApiClient(val baseUrl: String) {
companion object {
@ -62,14 +58,7 @@ open class ApiClient(val baseUrl: String) {
return null
}
return when(mediaType) {
JsonMediaType -> Moshi.Builder()
.add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe())
.add(LocalDateTimeAdapter())
.add(LocalDateAdapter())
.add(UUIDAdapter())
.add(ByteArrayAdapter())
.add(KotlinJsonAdapterFactory())
.build().adapter(T::class.java).fromJson(bodyContent)
JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent)
else -> TODO("responseBody currently only supports JSON body.")
}
}

View File

@ -1,8 +1,8 @@
package org.openapitools.client.infrastructure
import com.squareup.moshi.KotlinJsonAdapterFactory
import com.squareup.moshi.Moshi
import com.squareup.moshi.Rfc3339DateJsonAdapter
import com.squareup.moshi.adapters.Rfc3339DateJsonAdapter
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import java.util.Date
object Serializer {