diff --git a/modules/openapi-generator-maven-plugin/examples/kotlin.xml b/modules/openapi-generator-maven-plugin/examples/kotlin.xml index 361cc59c996..32f2e262741 100644 --- a/modules/openapi-generator-maven-plugin/examples/kotlin.xml +++ b/modules/openapi-generator-maven-plugin/examples/kotlin.xml @@ -238,7 +238,7 @@ 4.8.1 1.5.10 1.8 - 1.8.0 + 1.12.0 2.2 diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/build.gradle.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/build.gradle.mustache index 71f26c258f2..b085084935e 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/build.gradle.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/build.gradle.mustache @@ -62,9 +62,11 @@ dependencies { {{^moshiCodeGen}} implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" implementation "com.squareup.moshi:moshi-kotlin:1.12.0" + implementation "com.squareup.moshi:moshi-adapters:1.12.0" {{/moshiCodeGen}} {{#moshiCodeGen}} implementation "com.squareup.moshi:moshi:1.12.0" + implementation "com.squareup.moshi:moshi-adapters:1.12.0" kapt "com.squareup.moshi:moshi-kotlin-codegen:1.12.0" {{/moshiCodeGen}} {{/moshi}} @@ -126,4 +128,4 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { freeCompilerArgs += "-Xopt-in=kotlinx.serialization.ExperimentalSerializationApi" } } -{{/kotlinx_serialization}} \ No newline at end of file +{{/kotlinx_serialization}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache index 64ab00cf9b6..572fbafbc80 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache @@ -55,6 +55,15 @@ import org.threeten.bp.LocalTime import org.threeten.bp.OffsetDateTime import org.threeten.bp.OffsetTime {{/threetenbp}} +{{#gson}} +import com.google.gson.reflect.TypeToken +{{/gson}} +{{#jackson}} +import com.fasterxml.jackson.core.type.TypeReference +{{/jackson}} +{{#moshi}} +import com.squareup.moshi.adapter +{{/moshi}} {{#nonPublicApi}}internal {{/nonPublicApi}}open class ApiClient(val baseUrl: String) { {{#nonPublicApi}}internal {{/nonPublicApi}}companion object { @@ -173,6 +182,9 @@ import org.threeten.bp.OffsetTime else -> throw UnsupportedOperationException("requestBody currently only supports JSON body and File body.") } + {{#moshi}} + @OptIn(ExperimentalStdlibApi::class) + {{/moshi}} protected inline fun responseBody(body: ResponseBody?, mediaType: String? = JsonMediaType): T? { if(body == null) { return null @@ -201,7 +213,7 @@ import org.threeten.bp.OffsetTime return f as T } return when(mediaType) { - JsonMediaType -> {{#moshi}}Serializer.moshi.adapter(T::class.java).fromJson(bodyContent){{/moshi}}{{#gson}}Serializer.gson.fromJson(bodyContent, T::class.java){{/gson}}{{#jackson}}Serializer.jacksonObjectMapper.readValue(bodyContent, T::class.java){{/jackson}}{{#kotlinx_serialization}}Serializer.jvmJson.decodeFromString(bodyContent){{/kotlinx_serialization}} + JsonMediaType -> {{#moshi}}Serializer.moshi.adapter().fromJson(bodyContent){{/moshi}}{{#gson}}Serializer.gson.fromJson(bodyContent, (object: TypeToken(){}).getType()){{/gson}}{{#jackson}}Serializer.jacksonObjectMapper.readValue(bodyContent, object: TypeReference() {}){{/jackson}}{{#kotlinx_serialization}}Serializer.jvmJson.decodeFromString(bodyContent){{/kotlinx_serialization}} else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") } } diff --git a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 8ba19ee8e15..9d8cfd8c184 100644 --- a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -22,6 +22,7 @@ import java.time.OffsetDateTime import java.time.OffsetTime import java.util.Date import java.util.Locale +import com.google.gson.reflect.TypeToken open class ApiClient(val baseUrl: String) { companion object { @@ -124,7 +125,7 @@ open class ApiClient(val baseUrl: String) { return f as T } return when(mediaType) { - JsonMediaType -> Serializer.gson.fromJson(bodyContent, T::class.java) + JsonMediaType -> Serializer.gson.fromJson(bodyContent, (object: TypeToken(){}).getType()) else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") } } diff --git a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 6cf2ef9b0d1..5db80e34f81 100644 --- a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -22,6 +22,7 @@ import java.time.OffsetDateTime import java.time.OffsetTime import java.util.Date import java.util.Locale +import com.fasterxml.jackson.core.type.TypeReference open class ApiClient(val baseUrl: String) { companion object { @@ -124,7 +125,7 @@ open class ApiClient(val baseUrl: String) { return f as T } return when(mediaType) { - JsonMediaType -> Serializer.jacksonObjectMapper.readValue(bodyContent, T::class.java) + JsonMediaType -> Serializer.jacksonObjectMapper.readValue(bodyContent, object: TypeReference() {}) else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") } } diff --git a/samples/client/petstore/kotlin-json-request-string/build.gradle b/samples/client/petstore/kotlin-json-request-string/build.gradle index 189e54f8195..614bd17172a 100644 --- a/samples/client/petstore/kotlin-json-request-string/build.gradle +++ b/samples/client/petstore/kotlin-json-request-string/build.gradle @@ -32,6 +32,7 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" implementation "com.squareup.moshi:moshi-kotlin:1.12.0" + implementation "com.squareup.moshi:moshi-adapters:1.12.0" implementation "com.squareup.okhttp3:okhttp:4.9.1" testImplementation "io.kotlintest:kotlintest-runner-junit5:3.4.2" } diff --git a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index fc157890883..2dfe0159d45 100644 --- a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -23,6 +23,7 @@ import java.time.OffsetDateTime import java.time.OffsetTime import java.util.Date import java.util.Locale +import com.squareup.moshi.adapter open class ApiClient(val baseUrl: String) { companion object { @@ -107,6 +108,7 @@ open class ApiClient(val baseUrl: String) { else -> throw UnsupportedOperationException("requestBody currently only supports JSON body and File body.") } + @OptIn(ExperimentalStdlibApi::class) protected inline fun responseBody(body: ResponseBody?, mediaType: String? = JsonMediaType): T? { if(body == null) { return null @@ -130,7 +132,7 @@ open class ApiClient(val baseUrl: String) { return f as T } return when(mediaType) { - JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent) + JsonMediaType -> Serializer.moshi.adapter().fromJson(bodyContent) else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") } } diff --git a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 8ba19ee8e15..9d8cfd8c184 100644 --- a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -22,6 +22,7 @@ import java.time.OffsetDateTime import java.time.OffsetTime import java.util.Date import java.util.Locale +import com.google.gson.reflect.TypeToken open class ApiClient(val baseUrl: String) { companion object { @@ -124,7 +125,7 @@ open class ApiClient(val baseUrl: String) { return f as T } return when(mediaType) { - JsonMediaType -> Serializer.gson.fromJson(bodyContent, T::class.java) + JsonMediaType -> Serializer.gson.fromJson(bodyContent, (object: TypeToken(){}).getType()) else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") } } diff --git a/samples/client/petstore/kotlin-moshi-codegen/build.gradle b/samples/client/petstore/kotlin-moshi-codegen/build.gradle index ff73803f4b6..7e8fe4d9039 100644 --- a/samples/client/petstore/kotlin-moshi-codegen/build.gradle +++ b/samples/client/petstore/kotlin-moshi-codegen/build.gradle @@ -31,6 +31,7 @@ test { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" implementation "com.squareup.moshi:moshi:1.12.0" + implementation "com.squareup.moshi:moshi-adapters:1.12.0" kapt "com.squareup.moshi:moshi-kotlin-codegen:1.12.0" implementation "com.squareup.okhttp3:okhttp:4.9.1" testImplementation "io.kotlintest:kotlintest-runner-junit5:3.4.2" diff --git a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index ae6e80e9506..bc8a5963fb6 100644 --- a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -22,6 +22,7 @@ import java.time.OffsetDateTime import java.time.OffsetTime import java.util.Date import java.util.Locale +import com.squareup.moshi.adapter open class ApiClient(val baseUrl: String) { companion object { @@ -106,6 +107,7 @@ open class ApiClient(val baseUrl: String) { else -> throw UnsupportedOperationException("requestBody currently only supports JSON body and File body.") } + @OptIn(ExperimentalStdlibApi::class) protected inline fun responseBody(body: ResponseBody?, mediaType: String? = JsonMediaType): T? { if(body == null) { return null @@ -124,7 +126,7 @@ open class ApiClient(val baseUrl: String) { return f as T } return when(mediaType) { - JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent) + JsonMediaType -> Serializer.moshi.adapter().fromJson(bodyContent) else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") } } diff --git a/samples/client/petstore/kotlin-nonpublic/build.gradle b/samples/client/petstore/kotlin-nonpublic/build.gradle index bb575e6e4bf..3de8b45b135 100644 --- a/samples/client/petstore/kotlin-nonpublic/build.gradle +++ b/samples/client/petstore/kotlin-nonpublic/build.gradle @@ -31,6 +31,7 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" implementation "com.squareup.moshi:moshi-kotlin:1.12.0" + implementation "com.squareup.moshi:moshi-adapters:1.12.0" implementation "com.squareup.okhttp3:okhttp:4.9.1" testImplementation "io.kotlintest:kotlintest-runner-junit5:3.4.2" } diff --git a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index ed34dce2446..924fb6cd4c8 100644 --- a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -22,6 +22,7 @@ import java.time.OffsetDateTime import java.time.OffsetTime import java.util.Date import java.util.Locale +import com.squareup.moshi.adapter internal open class ApiClient(val baseUrl: String) { internal companion object { @@ -106,6 +107,7 @@ internal open class ApiClient(val baseUrl: String) { else -> throw UnsupportedOperationException("requestBody currently only supports JSON body and File body.") } + @OptIn(ExperimentalStdlibApi::class) protected inline fun responseBody(body: ResponseBody?, mediaType: String? = JsonMediaType): T? { if(body == null) { return null @@ -124,7 +126,7 @@ internal open class ApiClient(val baseUrl: String) { return f as T } return when(mediaType) { - JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent) + JsonMediaType -> Serializer.moshi.adapter().fromJson(bodyContent) else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") } } diff --git a/samples/client/petstore/kotlin-nullable/build.gradle b/samples/client/petstore/kotlin-nullable/build.gradle index bb575e6e4bf..3de8b45b135 100644 --- a/samples/client/petstore/kotlin-nullable/build.gradle +++ b/samples/client/petstore/kotlin-nullable/build.gradle @@ -31,6 +31,7 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" implementation "com.squareup.moshi:moshi-kotlin:1.12.0" + implementation "com.squareup.moshi:moshi-adapters:1.12.0" implementation "com.squareup.okhttp3:okhttp:4.9.1" testImplementation "io.kotlintest:kotlintest-runner-junit5:3.4.2" } diff --git a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index ae6e80e9506..bc8a5963fb6 100644 --- a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -22,6 +22,7 @@ import java.time.OffsetDateTime import java.time.OffsetTime import java.util.Date import java.util.Locale +import com.squareup.moshi.adapter open class ApiClient(val baseUrl: String) { companion object { @@ -106,6 +107,7 @@ open class ApiClient(val baseUrl: String) { else -> throw UnsupportedOperationException("requestBody currently only supports JSON body and File body.") } + @OptIn(ExperimentalStdlibApi::class) protected inline fun responseBody(body: ResponseBody?, mediaType: String? = JsonMediaType): T? { if(body == null) { return null @@ -124,7 +126,7 @@ open class ApiClient(val baseUrl: String) { return f as T } return when(mediaType) { - JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent) + JsonMediaType -> Serializer.moshi.adapter().fromJson(bodyContent) else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") } } diff --git a/samples/client/petstore/kotlin-okhttp3/build.gradle b/samples/client/petstore/kotlin-okhttp3/build.gradle index 4d9f2f630d4..b19a3b3873d 100644 --- a/samples/client/petstore/kotlin-okhttp3/build.gradle +++ b/samples/client/petstore/kotlin-okhttp3/build.gradle @@ -31,6 +31,7 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" implementation "com.squareup.moshi:moshi-kotlin:1.12.0" + implementation "com.squareup.moshi:moshi-adapters:1.12.0" implementation "com.squareup.okhttp3:okhttp:3.12.13" testImplementation "io.kotlintest:kotlintest-runner-junit5:3.4.2" } diff --git a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 538c66cec2e..b591a6d5e50 100644 --- a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -20,6 +20,7 @@ import java.time.OffsetDateTime import java.time.OffsetTime import java.util.Date import java.util.Locale +import com.squareup.moshi.adapter open class ApiClient(val baseUrl: String) { companion object { @@ -104,6 +105,7 @@ open class ApiClient(val baseUrl: String) { else -> throw UnsupportedOperationException("requestBody currently only supports JSON body and File body.") } + @OptIn(ExperimentalStdlibApi::class) protected inline fun responseBody(body: ResponseBody?, mediaType: String? = JsonMediaType): T? { if(body == null) { return null @@ -122,7 +124,7 @@ open class ApiClient(val baseUrl: String) { return f as T } return when(mediaType) { - JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent) + JsonMediaType -> Serializer.moshi.adapter().fromJson(bodyContent) else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") } } diff --git a/samples/client/petstore/kotlin-retrofit2-rx3/build.gradle b/samples/client/petstore/kotlin-retrofit2-rx3/build.gradle index 2f5e94a4fcd..0d9707eb2d9 100644 --- a/samples/client/petstore/kotlin-retrofit2-rx3/build.gradle +++ b/samples/client/petstore/kotlin-retrofit2-rx3/build.gradle @@ -33,6 +33,7 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" implementation "com.squareup.moshi:moshi-kotlin:1.12.0" + implementation "com.squareup.moshi:moshi-adapters:1.12.0" implementation "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:1.0.2" implementation "com.squareup.okhttp3:logging-interceptor:4.9.1" implementation "io.reactivex.rxjava3:rxjava:$rxJava3Version" diff --git a/samples/client/petstore/kotlin-retrofit2/build.gradle b/samples/client/petstore/kotlin-retrofit2/build.gradle index ec9a8e9ac24..32e67f975a8 100644 --- a/samples/client/petstore/kotlin-retrofit2/build.gradle +++ b/samples/client/petstore/kotlin-retrofit2/build.gradle @@ -32,6 +32,7 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" implementation "com.squareup.moshi:moshi-kotlin:1.12.0" + implementation "com.squareup.moshi:moshi-adapters:1.12.0" implementation "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:1.0.2" implementation "com.squareup.okhttp3:logging-interceptor:4.9.1" implementation "com.squareup.retrofit2:retrofit:$retrofitVersion" diff --git a/samples/client/petstore/kotlin-string/build.gradle b/samples/client/petstore/kotlin-string/build.gradle index bb575e6e4bf..3de8b45b135 100644 --- a/samples/client/petstore/kotlin-string/build.gradle +++ b/samples/client/petstore/kotlin-string/build.gradle @@ -31,6 +31,7 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" implementation "com.squareup.moshi:moshi-kotlin:1.12.0" + implementation "com.squareup.moshi:moshi-adapters:1.12.0" implementation "com.squareup.okhttp3:okhttp:4.9.1" testImplementation "io.kotlintest:kotlintest-runner-junit5:3.4.2" } 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 ae6e80e9506..bc8a5963fb6 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 @@ -22,6 +22,7 @@ import java.time.OffsetDateTime import java.time.OffsetTime import java.util.Date import java.util.Locale +import com.squareup.moshi.adapter open class ApiClient(val baseUrl: String) { companion object { @@ -106,6 +107,7 @@ open class ApiClient(val baseUrl: String) { else -> throw UnsupportedOperationException("requestBody currently only supports JSON body and File body.") } + @OptIn(ExperimentalStdlibApi::class) protected inline fun responseBody(body: ResponseBody?, mediaType: String? = JsonMediaType): T? { if(body == null) { return null @@ -124,7 +126,7 @@ open class ApiClient(val baseUrl: String) { return f as T } return when(mediaType) { - JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent) + JsonMediaType -> Serializer.moshi.adapter().fromJson(bodyContent) else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") } } diff --git a/samples/client/petstore/kotlin-threetenbp/build.gradle b/samples/client/petstore/kotlin-threetenbp/build.gradle index b4e0d0acc7a..39e3e411643 100644 --- a/samples/client/petstore/kotlin-threetenbp/build.gradle +++ b/samples/client/petstore/kotlin-threetenbp/build.gradle @@ -31,6 +31,7 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" implementation "com.squareup.moshi:moshi-kotlin:1.12.0" + implementation "com.squareup.moshi:moshi-adapters:1.12.0" implementation "com.squareup.okhttp3:okhttp:4.9.1" implementation "org.threeten:threetenbp:1.5.1" testImplementation "io.kotlintest:kotlintest-runner-junit5:3.4.2" 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 ad394bbefb0..a7441f81d1b 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 @@ -22,6 +22,7 @@ import org.threeten.bp.LocalDateTime import org.threeten.bp.LocalTime import org.threeten.bp.OffsetDateTime import org.threeten.bp.OffsetTime +import com.squareup.moshi.adapter open class ApiClient(val baseUrl: String) { companion object { @@ -106,6 +107,7 @@ open class ApiClient(val baseUrl: String) { else -> throw UnsupportedOperationException("requestBody currently only supports JSON body and File body.") } + @OptIn(ExperimentalStdlibApi::class) protected inline fun responseBody(body: ResponseBody?, mediaType: String? = JsonMediaType): T? { if(body == null) { return null @@ -124,7 +126,7 @@ open class ApiClient(val baseUrl: String) { return f as T } return when(mediaType) { - JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent) + JsonMediaType -> Serializer.moshi.adapter().fromJson(bodyContent) else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") } } diff --git a/samples/client/petstore/kotlin-uppercase-enum/build.gradle b/samples/client/petstore/kotlin-uppercase-enum/build.gradle index bb575e6e4bf..3de8b45b135 100644 --- a/samples/client/petstore/kotlin-uppercase-enum/build.gradle +++ b/samples/client/petstore/kotlin-uppercase-enum/build.gradle @@ -31,6 +31,7 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" implementation "com.squareup.moshi:moshi-kotlin:1.12.0" + implementation "com.squareup.moshi:moshi-adapters:1.12.0" implementation "com.squareup.okhttp3:okhttp:4.9.1" testImplementation "io.kotlintest:kotlintest-runner-junit5:3.4.2" } diff --git a/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index e65bce97f7e..b359be1e41d 100644 --- a/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -22,6 +22,7 @@ import java.time.OffsetDateTime import java.time.OffsetTime import java.util.Date import java.util.Locale +import com.squareup.moshi.adapter open class ApiClient(val baseUrl: String) { companion object { @@ -106,6 +107,7 @@ open class ApiClient(val baseUrl: String) { else -> throw UnsupportedOperationException("requestBody currently only supports JSON body and File body.") } + @OptIn(ExperimentalStdlibApi::class) protected inline fun responseBody(body: ResponseBody?, mediaType: String? = JsonMediaType): T? { if(body == null) { return null @@ -124,7 +126,7 @@ open class ApiClient(val baseUrl: String) { return f as T } return when(mediaType) { - JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent) + JsonMediaType -> Serializer.moshi.adapter().fromJson(bodyContent) else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") } } diff --git a/samples/client/petstore/kotlin/build.gradle b/samples/client/petstore/kotlin/build.gradle index bb575e6e4bf..3de8b45b135 100644 --- a/samples/client/petstore/kotlin/build.gradle +++ b/samples/client/petstore/kotlin/build.gradle @@ -31,6 +31,7 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" implementation "com.squareup.moshi:moshi-kotlin:1.12.0" + implementation "com.squareup.moshi:moshi-adapters:1.12.0" implementation "com.squareup.okhttp3:okhttp:4.9.1" testImplementation "io.kotlintest:kotlintest-runner-junit5:3.4.2" } diff --git a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index ae6e80e9506..bc8a5963fb6 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -22,6 +22,7 @@ import java.time.OffsetDateTime import java.time.OffsetTime import java.util.Date import java.util.Locale +import com.squareup.moshi.adapter open class ApiClient(val baseUrl: String) { companion object { @@ -106,6 +107,7 @@ open class ApiClient(val baseUrl: String) { else -> throw UnsupportedOperationException("requestBody currently only supports JSON body and File body.") } + @OptIn(ExperimentalStdlibApi::class) protected inline fun responseBody(body: ResponseBody?, mediaType: String? = JsonMediaType): T? { if(body == null) { return null @@ -124,7 +126,7 @@ open class ApiClient(val baseUrl: String) { return f as T } return when(mediaType) { - JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent) + JsonMediaType -> Serializer.moshi.adapter().fromJson(bodyContent) else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") } }