Hello, guys. I am currently making a simple tornad...
# serialization
a
Hello, guys. I am currently making a simple tornadofx GUI to generate a XML configuration. I believer that in order to do so, the simplest way is to make my model classes seializable and use @pdvrieze's xmlutil and make my model classes seializable. In order to do so, I need to create custom serializators for javafx Properties. Like this:
Copy code
@Serializer(forClass = StringProperty::class)
object StringPropertySerializer : KSerializer<StringProperty> {

    override val descriptor: SerialDescriptor = StringDescriptor

    override fun serialize(encoder: Encoder, obj: StringProperty) {
        encoder.encodeString(obj.value)
    }

    override fun deserialize(decoder: Decoder): StringProperty {
        return SimpleStringProperty(decoder.decodeString())
    }
}
I have two questions: 1. The property is nullable, how can I create a descriptor for nullable value. In @pdvrieze's code there is a delegate wrapper that copies descriptor functionality and switches the
nullable
flag. Is i the best way to do so. Do I even need the flag 2. Serialized xml seems to have class names for tag names instead of names of the peoperties. Is it something in serializaition, or a feature of
xmlutil
? 3. How can I tell enums to be serializaed into their names. Do I need custom serialized for that?
s
You usually wrap serializer into
NullableSerializer
and it wraps descriptor automatically
a
Thanks. I will try it.