mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-19 19:07:05 +00:00
[BUG][Kotlin] Add support for collection of generic classes (Jackson / Gson / Moshi) (#9918)
* Cherry picked commits from add-support-for-collection-of-generic-classes * Regenerated samples * Missing work by @adamsz-lume * Try to fix maven plugin error Co-authored-by: Bruno Coelho <4brunu@gmail.com>
This commit is contained in:
@@ -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 <reified T: Any?> 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<T>().fromJson(bodyContent)
|
||||
else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user