mirror of
https://github.com/apple/pkl.git
synced 2026-03-27 19:41:18 +01:00
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:
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user