Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quilt Config via Kotlinx Serialization #13

Open
Oliver-makes-code opened this issue Jun 11, 2022 · 6 comments
Open

Quilt Config via Kotlinx Serialization #13

Oliver-makes-code opened this issue Jun 11, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@Oliver-makes-code
Copy link
Contributor

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

@Oliver-makes-code Oliver-makes-code added the enhancement New feature or request label Jun 11, 2022
@Kroppeb
Copy link

Kroppeb commented Jun 16, 2022

This issue is a bit to vague ihmo. What exactly is the goal?

@Oliver-makes-code
Copy link
Contributor Author

The goal is to be able to use a preexisting serializable class with the quilt config system

@Kroppeb
Copy link

Kroppeb commented Jun 16, 2022

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?

@Oliver-makes-code
Copy link
Contributor Author

Oliver-makes-code commented Jun 16, 2022

@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

@Oliver-makes-code
Copy link
Contributor Author

@NoComment1105 has more experience with kotlinx serialization, so they might be able to help more with this

@Kroppeb
Copy link

Kroppeb commented Jun 16, 2022

ok that is the Kotlinx serialization part, but how does it "connect" to configs?

  • How does a config update when I change the value of name in custom
  • How does this data update when the config changes
  • What about default values? Each entry needs a default value

(Also fyi: custom serializers don't automatically get used like that)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants