Skip to content

Commit

Permalink
Explicitly define toString() for AtpEnums.
Browse files Browse the repository at this point in the history
Otherwise the data class/object's autogenerated toString() method takes
priotity, and won't return the proper token value when being serialized
in network requests.

Fixes #15
  • Loading branch information
christiandeange committed Dec 28, 2024
1 parent 39ed488 commit a230561
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,13 @@ fun createOpenEnumClass(
.build()
)

val superToString: FunSpec =
FunSpec.builder("toString")
.addModifiers(KModifier.OVERRIDE)
.returns(STRING)
.addStatement("return super.toString()")
.build()

val valueOfControlFlow = CodeBlock.builder()
.beginControlFlow("return when (value)")

Expand All @@ -270,6 +277,7 @@ fun createOpenEnumClass(
.addDescription(entry.description)
.superclass(className)
.addSuperclassConstructorParameter("%S", entry.name)
.addFunction(superToString)
.build()
)
}
Expand Down

0 comments on commit a230561

Please sign in to comment.