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

Empty Files created when using Kotlin Classes without "extras-kotlin" module #526

Open
xMrAfonso opened this issue Nov 16, 2024 · 0 comments

Comments

@xMrAfonso
Copy link

xMrAfonso commented Nov 16, 2024

I've been using Configurate with Kotlin and encountered some issues. The extras-kotlin module mentions that it adds support for data classes. I assumed this meant normal Kotlin classes would be fully supported out of the box. However, when attempting to create configurations with normal Kotlin classes, the files are created but remain empty with no errors being present on the console.

I'm unsure if this behavior is intended or if I'm missing something in my setup.

Why I'm Not Using extra-kotlin:
I'm not using the extra-kotlin module because it depends on kotlin-reflect, which has known compatibility issues with Paper loaders. Additionally, shading kotlin-reflect properly into my project has been problematic.

Method Used to Create Configurations:
Here’s the method I use to create and load configurations:

private fun <T> create(clazz: Class<T>, fileName: String): T? {
    try {
        Files.createDirectories(dataFolder)

        val path: Path = dataFolder.resolve(fileName)

        val loader: YamlConfigurationLoader = loader(path)
        val node: CommentedConfigurationNode = loader.load()
        val config = node.get(clazz)

        if (!Files.exists(path)) {
            Files.createFile(path)
            node.set(clazz, config)
        }

        loader.save(node)
        return config
    } catch (exception: IOException) {
        exception.printStackTrace()
    }
    return null
}

Possible Cause:
I suspect the issue might be related to the object mapper since Kotlin has its own quirks compared to Java. If that's the case, the documentation should specify that the extra-kotlin module not only supports data classes but also provides full support for normal Kotlin classes.

Expected Behavior:

  • Normal Kotlin classes should be supported out of the box without requiring the extra-kotlin module.
  • If additional dependencies like kotlin-reflect are mandatory, this should be clarified in the documentation.

Let me know if I’m missing something or if this is unintended behavior.

PS: Since I usually don't express myself very well, this message was formatted by AI and rechecked after by me to make sure both parties understand it clearly.

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

No branches or pull requests

1 participant