mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-06 10:35:25 +00:00
[KOTLIN client] fix Moshi (Serializer/Deserializer) duplicated (#3013)
This commit is contained in:
parent
d1043c910c
commit
d748312818
@ -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"
|
||||
}
|
||||
|
@ -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.")
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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"
|
||||
}
|
||||
|
@ -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.")
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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"
|
||||
}
|
||||
|
@ -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.")
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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"
|
||||
}
|
||||
|
@ -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.")
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user