mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-03 08:46:55 +00:00
feat(adapter): add BigDecimal kotlin support (#8880)
* feat(adapter): add BigDecimal kotlin support this allows the kotlin client generator to support BigDecimal values Fixes #7196 * update samples Co-authored-by: William Cheng <wing328hk@gmail.com>
This commit is contained in:
@@ -21,6 +21,8 @@ src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt
|
||||
src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt
|
||||
src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt
|
||||
src/main/kotlin/org/openapitools/client/infrastructure/ApplicationDelegates.kt
|
||||
src/main/kotlin/org/openapitools/client/infrastructure/BigDecimalAdapter.kt
|
||||
src/main/kotlin/org/openapitools/client/infrastructure/BigIntegerAdapter.kt
|
||||
src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt
|
||||
src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt
|
||||
src/main/kotlin/org/openapitools/client/infrastructure/LocalDateAdapter.kt
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import com.squareup.moshi.FromJson
|
||||
import com.squareup.moshi.ToJson
|
||||
import java.math.BigDecimal
|
||||
|
||||
class BigDecimalAdapter {
|
||||
@ToJson
|
||||
fun toJson(value: BigDecimal): String {
|
||||
return value.toPlainString()
|
||||
}
|
||||
|
||||
@FromJson
|
||||
fun fromJson(value: String): BigDecimal {
|
||||
return BigDecimal(value)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import com.squareup.moshi.FromJson
|
||||
import com.squareup.moshi.ToJson
|
||||
import java.math.BigInteger
|
||||
|
||||
class BigIntegerAdapter {
|
||||
@ToJson
|
||||
fun toJson(value: BigInteger): String {
|
||||
return value.toString()
|
||||
}
|
||||
|
||||
@FromJson
|
||||
fun fromJson(value: String): BigInteger {
|
||||
return BigInteger(value)
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,8 @@ object Serializer {
|
||||
.add(UUIDAdapter())
|
||||
.add(ByteArrayAdapter())
|
||||
.add(KotlinJsonAdapterFactory())
|
||||
.add(BigDecimalAdapter())
|
||||
.add(BigIntegerAdapter())
|
||||
|
||||
@JvmStatic
|
||||
val moshi: Moshi by lazy {
|
||||
|
||||
Reference in New Issue
Block a user