forked from OpenAPITools/openapi-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added BigDecimalAdapter and BigIntegerAdapter adapter for Kotlin Clie…
…nt Moshi
- Loading branch information
Showing
45 changed files
with
424 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 18 additions & 2 deletions
20
.../src/main/resources/kotlin-client/jvm-common/infrastructure/BigDecimalAdapter.kt.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,35 @@ | ||
package {{packageName}}.infrastructure | ||
|
||
{{#kotlinx_serialization}} | ||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.Serializer | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor | ||
import kotlinx.serialization.descriptors.PrimitiveKind | ||
import kotlinx.serialization.descriptors.SerialDescriptor | ||
{{/kotlinx_serialization}} | ||
{{#moshi}} | ||
import com.squareup.moshi.FromJson | ||
import com.squareup.moshi.ToJson | ||
{{/moshi}} | ||
import java.math.BigDecimal | ||
|
||
@Serializer(forClass = BigDecimal::class) | ||
{{#kotlinx_serialization}}@Serializer(forClass = BigDecimal::class) | ||
object BigDecimalAdapter : KSerializer<BigDecimal> { | ||
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("BigDecimal", PrimitiveKind.STRING) | ||
override fun deserialize(decoder: Decoder): BigDecimal = BigDecimal(decoder.decodeString()) | ||
override fun serialize(encoder: Encoder, value: BigDecimal) = encoder.encodeString(value.toPlainString()) | ||
} | ||
}{{/kotlinx_serialization}}{{#moshi}}{{#nonPublicApi}}internal {{/nonPublicApi}}class BigDecimalAdapter { | ||
@ToJson | ||
fun toJson(value: BigDecimal): String { | ||
return value.toPlainString() | ||
} | ||
|
||
@FromJson | ||
fun fromJson(value: String): BigDecimal { | ||
return BigDecimal(value) | ||
} | ||
}{{/moshi}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...equest-string/src/main/kotlin/org/openapitools/client/infrastructure/BigDecimalAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...equest-string/src/main/kotlin/org/openapitools/client/infrastructure/BigIntegerAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/BigDecimalAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/BigIntegerAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...lin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/BigDecimalAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.openapitools.client.infrastructure | ||
|
||
import com.squareup.moshi.FromJson | ||
import com.squareup.moshi.ToJson | ||
import java.math.BigDecimal | ||
|
||
internal class BigDecimalAdapter { | ||
@ToJson | ||
fun toJson(value: BigDecimal): String { | ||
return value.toPlainString() | ||
} | ||
|
||
@FromJson | ||
fun fromJson(value: String): BigDecimal { | ||
return BigDecimal(value) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...lin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/BigIntegerAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.openapitools.client.infrastructure | ||
|
||
import com.squareup.moshi.FromJson | ||
import com.squareup.moshi.ToJson | ||
import java.math.BigInteger | ||
|
||
internal class BigIntegerAdapter { | ||
@ToJson | ||
fun toJson(value: BigInteger): String { | ||
return value.toString() | ||
} | ||
|
||
@FromJson | ||
fun fromJson(value: String): BigInteger { | ||
return BigInteger(value) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...tlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/BigDecimalAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...tlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/BigIntegerAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...otlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/BigDecimalAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
Oops, something went wrong.