codegen-kotlin: Support Java serialization of module classes (#721)

Motivation:
- Java serialization makes as much sense for module classes as it does for regular classes.
- Offer same Java serialization support as codegen-java.

Changes:
- Move generation of `appendProperty` method and serialization code
  into new method `generateCompanionRelatedCode`.
- Improve/fix generation of serialization code.

Result:
Java serialization is also supported for module classes.
This commit is contained in:
translatenix
2024-10-24 22:11:35 -07:00
committed by GitHub
parent 8b0118fec5
commit 8fa3acf32f
2 changed files with 113 additions and 76 deletions

View File

@@ -1760,6 +1760,45 @@ class KotlinCodeGeneratorTest {
confirmSerDe(bigStruct)
}
@Test
fun `generates serializable module classes`() {
val kotlinCode =
generateKotlinCode(
"""
module Person
address: Address
class Address {
street: String
}
""",
implementSerializable = true
)
assertThat(kotlinCode)
.contains(
"""
|data class Person(
| val address: Address
|) : Serializable {
| data class Address(
| val street: String
| ) : Serializable {
| companion object {
| private const val serialVersionUID: Long = 0L
| }
| }
|
| companion object {
| private const val serialVersionUID: Long = 0L
| }
|}
"""
.trimMargin()
)
}
@Test
fun `encoded file paths`() {
val kotlinCode =