Greg Steckman
09/20/2020, 5:10 PM@Serializable
class OuterTestClass(val x: Int){
val inner = InnerTestClass(5)
@Serializable
inner class InnerTestClass(val y: Int){
fun compute(): Int{
return x*y
}
}
}
Example test, where a null pointer exception is thrown at the call to o2.inner.compute():
@Test
fun testInnerClassesAreSerializable(){
val o1 = OuterTestClass(3)
val str = Json.encodeToString(o1)
val o2 = Json.decodeFromString<OuterTestClass>(str)
assertEquals(o1.x, o2.x)
assertEquals(o1.inner.y, o2.inner.y)
assertEquals(o1.inner.compute(), o2.inner.compute())
}
The intermediate JSON string looks like what I would expect: {"x":3,"inner":{"y":5}}
I am using Kotlin 1.4.10 and Kotlinx Serialization version 1.0.0-RC. I checked the serialization documentation for any exclusions for inner class support but didn't find anything that looked relevant, and also checked open issues on Github. Does anyone know if this is an intentional unsupported use case, or otherwise a known open issue? Thanks.sandwwraith
09/21/2020, 3:32 PM