[Kotlin][Client] Enum toString handling (#5327)

* Added toString to enum_class script

This toString avoids using the enum var name and uses the enum's value instead. This will fix cases when enum var name and value are quite different.

* Updated enum template

Co-Authored-By: Jim Schubert <james.schubert@gmail.com>

Co-authored-by: Jim Schubert <james.schubert@gmail.com>
This commit is contained in:
Alexander Eggers
2020-02-19 13:30:13 +11:00
committed by GitHub
parent db47b95fc9
commit a7f2791783

View File

@@ -41,6 +41,14 @@ import kotlinx.serialization.internal.CommonEnumSerializer
{{/enumVars}}{{/allowableValues}}
/**
This override toString avoids using the enum var name and uses the actual api value instead.
In cases the var name and value are different, the client would send incorrect enums to the server.
**/
override fun toString(): String {
return value{{^isString}}.toString(){{/isString}}
}
{{#multiplatform}}
{{#nonPublicApi}}internal {{/nonPublicApi}}object Serializer : CommonEnumSerializer<{{classname}}>("{{classname}}", values(), values().map { it.value.toString() }.toTypedArray())
{{/multiplatform}}