forked from loafle/openapi-generator-original
[Kotlin] Fix parse error when using custom field names with @Json (#2944)
* Fix to use isEmpty method * Add KotlinJsonAdapterFactory to moshi adapter * Update petstore sample
This commit is contained in:
parent
6a1f33d2f8
commit
1e06d7fe88
@ -1,6 +1,7 @@
|
|||||||
package {{packageName}}.infrastructure
|
package {{packageName}}.infrastructure
|
||||||
|
|
||||||
import com.squareup.moshi.FromJson
|
import com.squareup.moshi.FromJson
|
||||||
|
import com.squareup.moshi.KotlinJsonAdapterFactory
|
||||||
import com.squareup.moshi.Moshi
|
import com.squareup.moshi.Moshi
|
||||||
import com.squareup.moshi.ToJson
|
import com.squareup.moshi.ToJson
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
@ -58,7 +59,7 @@ open class ApiClient(val baseUrl: String) {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
val bodyContent = body.string()
|
val bodyContent = body.string()
|
||||||
if (bodyContent.length == 0) {
|
if (bodyContent.isEmpty()) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
return when(mediaType) {
|
return when(mediaType) {
|
||||||
@ -69,6 +70,7 @@ open class ApiClient(val baseUrl: String) {
|
|||||||
fun fromJson(s: String) = UUID.fromString(s)
|
fun fromJson(s: String) = UUID.fromString(s)
|
||||||
})
|
})
|
||||||
.add(ByteArrayAdapter())
|
.add(ByteArrayAdapter())
|
||||||
|
.add(KotlinJsonAdapterFactory())
|
||||||
.build().adapter(T::class.java).fromJson(bodyContent)
|
.build().adapter(T::class.java).fromJson(bodyContent)
|
||||||
else -> TODO("responseBody currently only supports JSON body.")
|
else -> TODO("responseBody currently only supports JSON body.")
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package org.openapitools.client.infrastructure
|
package org.openapitools.client.infrastructure
|
||||||
|
|
||||||
import com.squareup.moshi.FromJson
|
import com.squareup.moshi.FromJson
|
||||||
|
import com.squareup.moshi.KotlinJsonAdapterFactory
|
||||||
import com.squareup.moshi.Moshi
|
import com.squareup.moshi.Moshi
|
||||||
import com.squareup.moshi.ToJson
|
import com.squareup.moshi.ToJson
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
@ -58,7 +59,7 @@ open class ApiClient(val baseUrl: String) {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
val bodyContent = body.string()
|
val bodyContent = body.string()
|
||||||
if (bodyContent.length == 0) {
|
if (bodyContent.isEmpty()) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
return when(mediaType) {
|
return when(mediaType) {
|
||||||
@ -69,6 +70,7 @@ open class ApiClient(val baseUrl: String) {
|
|||||||
fun fromJson(s: String) = UUID.fromString(s)
|
fun fromJson(s: String) = UUID.fromString(s)
|
||||||
})
|
})
|
||||||
.add(ByteArrayAdapter())
|
.add(ByteArrayAdapter())
|
||||||
|
.add(KotlinJsonAdapterFactory())
|
||||||
.build().adapter(T::class.java).fromJson(bodyContent)
|
.build().adapter(T::class.java).fromJson(bodyContent)
|
||||||
else -> TODO("responseBody currently only supports JSON body.")
|
else -> TODO("responseBody currently only supports JSON body.")
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package org.openapitools.client.infrastructure
|
package org.openapitools.client.infrastructure
|
||||||
|
|
||||||
import com.squareup.moshi.FromJson
|
import com.squareup.moshi.FromJson
|
||||||
|
import com.squareup.moshi.KotlinJsonAdapterFactory
|
||||||
import com.squareup.moshi.Moshi
|
import com.squareup.moshi.Moshi
|
||||||
import com.squareup.moshi.ToJson
|
import com.squareup.moshi.ToJson
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
@ -58,7 +59,7 @@ open class ApiClient(val baseUrl: String) {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
val bodyContent = body.string()
|
val bodyContent = body.string()
|
||||||
if (bodyContent.length == 0) {
|
if (bodyContent.isEmpty()) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
return when(mediaType) {
|
return when(mediaType) {
|
||||||
@ -69,6 +70,7 @@ open class ApiClient(val baseUrl: String) {
|
|||||||
fun fromJson(s: String) = UUID.fromString(s)
|
fun fromJson(s: String) = UUID.fromString(s)
|
||||||
})
|
})
|
||||||
.add(ByteArrayAdapter())
|
.add(ByteArrayAdapter())
|
||||||
|
.add(KotlinJsonAdapterFactory())
|
||||||
.build().adapter(T::class.java).fromJson(bodyContent)
|
.build().adapter(T::class.java).fromJson(bodyContent)
|
||||||
else -> TODO("responseBody currently only supports JSON body.")
|
else -> TODO("responseBody currently only supports JSON body.")
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package org.openapitools.client.infrastructure
|
package org.openapitools.client.infrastructure
|
||||||
|
|
||||||
import com.squareup.moshi.FromJson
|
import com.squareup.moshi.FromJson
|
||||||
|
import com.squareup.moshi.KotlinJsonAdapterFactory
|
||||||
import com.squareup.moshi.Moshi
|
import com.squareup.moshi.Moshi
|
||||||
import com.squareup.moshi.ToJson
|
import com.squareup.moshi.ToJson
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
@ -58,7 +59,7 @@ open class ApiClient(val baseUrl: String) {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
val bodyContent = body.string()
|
val bodyContent = body.string()
|
||||||
if (bodyContent.length == 0) {
|
if (bodyContent.isEmpty()) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
return when(mediaType) {
|
return when(mediaType) {
|
||||||
@ -69,6 +70,7 @@ open class ApiClient(val baseUrl: String) {
|
|||||||
fun fromJson(s: String) = UUID.fromString(s)
|
fun fromJson(s: String) = UUID.fromString(s)
|
||||||
})
|
})
|
||||||
.add(ByteArrayAdapter())
|
.add(ByteArrayAdapter())
|
||||||
|
.add(KotlinJsonAdapterFactory())
|
||||||
.build().adapter(T::class.java).fromJson(bodyContent)
|
.build().adapter(T::class.java).fromJson(bodyContent)
|
||||||
else -> TODO("responseBody currently only supports JSON body.")
|
else -> TODO("responseBody currently only supports JSON body.")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user