Skip to content

Commit

Permalink
[kotlin][client] Kotlinx Serialization code formating (#12922)
Browse files Browse the repository at this point in the history
* [kotlin][client] Kotlinx Serialization cleanup

* [kotlin][client] Kotlinx Serialization cleanup
  • Loading branch information
4brunu authored Jul 19, 2022
1 parent 1a5b592 commit 8d62e59
Show file tree
Hide file tree
Showing 60 changed files with 79 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -596,13 +596,13 @@ private void processJVMVolleyLibrary(String infrastructureFolder, String request

private void addSupportingSerializerAdapters(final String infrastructureFolder) {
supportingFiles.add(new SupportingFile("jvm-common/infrastructure/Serializer.kt.mustache", infrastructureFolder, "Serializer.kt"));
supportingFiles.add(new SupportingFile("jvm-common/infrastructure/ByteArrayAdapter.kt.mustache", infrastructureFolder, "ByteArrayAdapter.kt"));

switch (getSerializationLibrary()) {
case moshi:
if (enumUnknownDefaultCase) {
supportingFiles.add(new SupportingFile("jvm-common/infrastructure/SerializerHelper.kt.mustache", infrastructureFolder, "SerializerHelper.kt"));
}
supportingFiles.add(new SupportingFile("jvm-common/infrastructure/ByteArrayAdapter.kt.mustache", infrastructureFolder, "ByteArrayAdapter.kt"));
supportingFiles.add(new SupportingFile("jvm-common/infrastructure/UUIDAdapter.kt.mustache", infrastructureFolder, "UUIDAdapter.kt"));
supportingFiles.add(new SupportingFile("jvm-common/infrastructure/LocalDateAdapter.kt.mustache", infrastructureFolder, "LocalDateAdapter.kt"));
supportingFiles.add(new SupportingFile("jvm-common/infrastructure/LocalDateTimeAdapter.kt.mustache", infrastructureFolder, "LocalDateTimeAdapter.kt"));
Expand All @@ -613,6 +613,7 @@ private void addSupportingSerializerAdapters(final String infrastructureFolder)
break;

case gson:
supportingFiles.add(new SupportingFile("jvm-common/infrastructure/ByteArrayAdapter.kt.mustache", infrastructureFolder, "ByteArrayAdapter.kt"));
supportingFiles.add(new SupportingFile("jvm-common/infrastructure/LocalDateAdapter.kt.mustache", infrastructureFolder, "LocalDateAdapter.kt"));
supportingFiles.add(new SupportingFile("jvm-common/infrastructure/LocalDateTimeAdapter.kt.mustache", infrastructureFolder, "LocalDateTimeAdapter.kt"));
supportingFiles.add(new SupportingFile("jvm-common/infrastructure/OffsetDateTimeAdapter.kt.mustache", infrastructureFolder, "OffsetDateTimeAdapter.kt"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import kotlinx.serialization.descriptors.SerialDescriptor
import java.util.concurrent.atomic.AtomicBoolean

@Serializer(forClass = AtomicBoolean::class)
object AtomicBooleanAdapter : KSerializer<AtomicBoolean> {
{{#nonPublicApi}}internal {{/nonPublicApi}}object AtomicBooleanAdapter : KSerializer<AtomicBoolean> {
override fun serialize(encoder: Encoder, value: AtomicBoolean) {
encoder.encodeBoolean(value.get())
}

override fun deserialize(decoder: Decoder): AtomicBoolean = AtomicBoolean(decoder.decodeBoolean())

override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("AtomicBoolean", PrimitiveKind.BOOLEAN)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import kotlinx.serialization.descriptors.SerialDescriptor
import java.util.concurrent.atomic.AtomicInteger

@Serializer(forClass = AtomicInteger::class)
object AtomicIntegerAdapter : KSerializer<AtomicInteger> {
{{#nonPublicApi}}internal {{/nonPublicApi}}object AtomicIntegerAdapter : KSerializer<AtomicInteger> {
override fun serialize(encoder: Encoder, value: AtomicInteger) {
encoder.encodeInt(value.get())
}

override fun deserialize(decoder: Decoder): AtomicInteger = AtomicInteger(decoder.decodeInt())

override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("AtomicInteger", PrimitiveKind.INT)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import kotlinx.serialization.descriptors.SerialDescriptor
import java.util.concurrent.atomic.AtomicLong

@Serializer(forClass = AtomicLong::class)
object AtomicLongAdapter : KSerializer<AtomicLong> {
{{#nonPublicApi}}internal {{/nonPublicApi}}object AtomicLongAdapter : KSerializer<AtomicLong> {
override fun serialize(encoder: Encoder, value: AtomicLong) {
encoder.encodeLong(value.get())
}

override fun deserialize(decoder: Decoder): AtomicLong = AtomicLong(decoder.decodeLong())

override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("AtomicLong", PrimitiveKind.LONG)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ import com.squareup.moshi.ToJson
{{/moshi}}
import java.math.BigDecimal

{{#kotlinx_serialization}}@Serializer(forClass = BigDecimal::class)
object BigDecimalAdapter : KSerializer<BigDecimal> {
{{#kotlinx_serialization}}
@Serializer(forClass = BigDecimal::class)
{{#nonPublicApi}}internal {{/nonPublicApi}}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 {
}
{{/kotlinx_serialization}}
{{#moshi}}
{{#nonPublicApi}}internal {{/nonPublicApi}}class BigDecimalAdapter {
@ToJson
fun toJson(value: BigDecimal): String {
return value.toPlainString()
Expand All @@ -30,4 +34,5 @@ object BigDecimalAdapter : KSerializer<BigDecimal> {
fun fromJson(value: String): BigDecimal {
return BigDecimal(value)
}
}{{/moshi}}
}
{{/moshi}}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import com.squareup.moshi.ToJson
{{/moshi}}
import java.math.BigInteger

{{#kotlinx_serialization}}@Serializer(forClass = BigInteger::class)
object BigIntegerAdapter : KSerializer<BigInteger> {
{{#kotlinx_serialization}}
@Serializer(forClass = BigInteger::class)
{{#nonPublicApi}}internal {{/nonPublicApi}}object BigIntegerAdapter : KSerializer<BigInteger> {
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("BigInteger", PrimitiveKind.STRING)
override fun deserialize(decoder: Decoder): BigInteger {
return BigInteger(decoder.decodeString())
Expand All @@ -25,7 +26,10 @@ object BigIntegerAdapter : KSerializer<BigInteger> {
override fun serialize(encoder: Encoder, value: BigInteger) {
encoder.encodeString(value.toString())
}
}{{/kotlinx_serialization}}{{#moshi}}{{#nonPublicApi}}internal {{/nonPublicApi}}class BigIntegerAdapter {
}
{{/kotlinx_serialization}}
{{#moshi}}
{{#nonPublicApi}}internal {{/nonPublicApi}}class BigIntegerAdapter {
@ToJson
fun toJson(value: BigInteger): String {
return value.toString()
Expand All @@ -35,4 +39,5 @@ object BigIntegerAdapter : KSerializer<BigInteger> {
fun fromJson(value: String): BigInteger {
return BigInteger(value)
}
}{{/moshi}}
}
{{/moshi}}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.SerialDescriptor

@Serializer(forClass = StringBuilder::class)
object StringBuilderAdapter : KSerializer<StringBuilder> {
{{#nonPublicApi}}internal {{/nonPublicApi}}object StringBuilderAdapter : KSerializer<StringBuilder> {
override fun serialize(encoder: Encoder, value: StringBuilder) {
encoder.encodeString(value.toString())
}

override fun deserialize(decoder: Decoder): StringBuilder = StringBuilder(decoder.decodeString())

override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("StringBuilder", PrimitiveKind.STRING)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import kotlinx.serialization.descriptors.SerialDescriptor
import java.net.URL

@Serializer(forClass = URL::class)
object URLAdapter : KSerializer<URL> {
{{#nonPublicApi}}internal {{/nonPublicApi}}object URLAdapter : KSerializer<URL> {
override fun serialize(encoder: Encoder, value: URL) {
encoder.encodeString(value.toExternalForm())
}

override fun deserialize(decoder: Decoder): URL = URL(decoder.decodeString())

override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("URL", PrimitiveKind.STRING)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
# project specific.
-keep,includedescriptorclasses class {{modelPackage}}.**$$serializer { *; }
-keepclassmembers class {{modelPackage}}.** { *** Companion; }
-keepclasseswithmembers class {{modelPackage}}.** { kotlinx.serialization.KSerializer serializer(...); }
-keepclasseswithmembers class {{modelPackage}}.** { kotlinx.serialization.KSerializer serializer(...); }
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class BigDecimalAdapter {
fun fromJson(value: String): BigDecimal {
return BigDecimal(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class BigIntegerAdapter {
fun fromJson(value: String): BigInteger {
return BigInteger(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class BigDecimalAdapter {
fun fromJson(value: String): BigDecimal {
return BigDecimal(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class BigIntegerAdapter {
fun fromJson(value: String): BigInteger {
return BigInteger(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class BigDecimalAdapter {
fun fromJson(value: String): BigDecimal {
return BigDecimal(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class BigIntegerAdapter {
fun fromJson(value: String): BigInteger {
return BigInteger(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class BigDecimalAdapter {
fun fromJson(value: String): BigDecimal {
return BigDecimal(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class BigIntegerAdapter {
fun fromJson(value: String): BigInteger {
return BigInteger(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class BigDecimalAdapter {
fun fromJson(value: String): BigDecimal {
return BigDecimal(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class BigIntegerAdapter {
fun fromJson(value: String): BigInteger {
return BigInteger(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class BigDecimalAdapter {
fun fromJson(value: String): BigDecimal {
return BigDecimal(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class BigIntegerAdapter {
fun fromJson(value: String): BigInteger {
return BigInteger(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class BigDecimalAdapter {
fun fromJson(value: String): BigDecimal {
return BigDecimal(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class BigIntegerAdapter {
fun fromJson(value: String): BigInteger {
return BigInteger(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class BigDecimalAdapter {
fun fromJson(value: String): BigDecimal {
return BigDecimal(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class BigIntegerAdapter {
fun fromJson(value: String): BigInteger {
return BigInteger(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ src/main/kotlin/org/openapitools/client/apis/UserApi.kt
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/ApiResponse.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/PartConfig.kt
src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class BigDecimalAdapter {
fun fromJson(value: String): BigDecimal {
return BigDecimal(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class BigIntegerAdapter {
fun fromJson(value: String): BigInteger {
return BigInteger(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class BigDecimalAdapter {
fun fromJson(value: String): BigDecimal {
return BigDecimal(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class BigIntegerAdapter {
fun fromJson(value: String): BigInteger {
return BigInteger(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class BigDecimalAdapter {
fun fromJson(value: String): BigDecimal {
return BigDecimal(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class BigIntegerAdapter {
fun fromJson(value: String): BigInteger {
return BigInteger(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ internal class BigDecimalAdapter {
fun fromJson(value: String): BigDecimal {
return BigDecimal(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ internal class BigIntegerAdapter {
fun fromJson(value: String): BigInteger {
return BigInteger(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class BigDecimalAdapter {
fun fromJson(value: String): BigDecimal {
return BigDecimal(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class BigIntegerAdapter {
fun fromJson(value: String): BigInteger {
return BigInteger(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class BigDecimalAdapter {
fun fromJson(value: String): BigDecimal {
return BigDecimal(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class BigIntegerAdapter {
fun fromJson(value: String): BigInteger {
return BigInteger(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ src/main/kotlin/org/openapitools/client/infrastructure/AtomicIntegerAdapter.kt
src/main/kotlin/org/openapitools/client/infrastructure/AtomicLongAdapter.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/CollectionFormats.kt
src/main/kotlin/org/openapitools/client/infrastructure/LocalDateAdapter.kt
src/main/kotlin/org/openapitools/client/infrastructure/LocalDateTimeAdapter.kt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
# project specific.
-keep,includedescriptorclasses class org.openapitools.client.models.**$$serializer { *; }
-keepclassmembers class org.openapitools.client.models.** { *** Companion; }
-keepclasseswithmembers class org.openapitools.client.models.** { kotlinx.serialization.KSerializer serializer(...); }
-keepclasseswithmembers class org.openapitools.client.models.** { kotlinx.serialization.KSerializer serializer(...); }
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ object AtomicBooleanAdapter : KSerializer<AtomicBoolean> {
override fun deserialize(decoder: Decoder): AtomicBoolean = AtomicBoolean(decoder.decodeBoolean())

override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("AtomicBoolean", PrimitiveKind.BOOLEAN)
}
}
Loading

0 comments on commit 8d62e59

Please sign in to comment.