Open Oliver-makes-code opened 2 years ago
This issue is a bit to vague ihmo. What exactly is the goal?
The goal is to be able to use a preexisting serializable class with the quilt config system
The goal is to be able to use a preexisting serializable class with the quilt config system
In what sense? Do you think you could give an example?
@Serializable
class SerializableClass {
var name: String = "Name" // Will be serialized into a string
var custom: Custom = Custom.apply {
name = "Test"
}
}
@Serializable
@SerialName("Custom")
class Custom {
var name: String
}
class CustomSerializaer : KSerializer<Custom> {
override fun serialize(encoder: Encoder, value: Custom) {
val string = value.name
encoder.encodeString(string)
}
override fun deserialize(decoder: Decoder): Custom {
val string = decoder.decodeString()
return Custom().apply {
name = string
}
}
}
This would get serialized into this (Assuming JSON5)
{
name: "Name",
custom: "Test!"
}
It can get more complex that that, though, with multiple properties in custom serializers
@NoComment1105 has more experience with kotlinx serialization, so they might be able to help more with this
ok that is the Kotlinx serialization part, but how does it "connect" to configs?
name
in custom
(Also fyi: custom serializers don't automatically get used like that)
Intro:
Jetbrains has a Kotlinx library that handles serialization of classes for config and other stuff. A bridge between this and Quilt Config would be beneficial to modders who are already familiar with Kotlinx Serialization
Existing Work:
Not any that I can find, mostly because Quilt Config is relatively new