# serialization


11/10/2023, 12:23 PM
Yaml / Kaml: Having some difficulty with a sealed class that has abstract properties which are not part of the primary constructor - the property is a lateinit var, but I get a MissingPropertyException. Sample code:
Copy code
sealed class Node {
  abstract var key: String
  data class PostNode(val title: String) : Node {
    override lateinit var key: String
And a sample yaml file might simply be:
Copy code
title: This is a post
Kaml can't deserialize this, as it says that "key" is required but missing. My understanding was that only properties in the primary constructor are required?
In the real implementation, there are other properties that aren't part of the
constructor, and they are working fine.
I've tested with Json instead of Yaml; same problem. The abstract property key is being treated as required.


11/10/2023, 4:36 PM
@Transient lateinit
should work
(that leaves it out of serialization, obviously)


11/10/2023, 4:47 PM
Yeah. Trouble is, I do want it for serialization, just not for deserialization... I'm trying to do too many things with one class, I think! So for now I've created a simpler class for my yaml, then copied its data in to my PostNode class.