Enum members returned by `LspServerDescriptor.getWorkspaceConfiguration()` are serialized as numbers

I have a LspServerDescriptor whose getWorkspaceConfiguration looks something like this:

@Serializable
enum class E {
    @SerialName("a") A,
    @SerialName("b") B;
}

@Serializable
data class WorkspaceConfiguration(
    val choice: E
)

override fun getWorkspaceConfiguration(item: ConfigurationItem) =
    when (item.section) {
        "somekey" -> WorkspaceConfiguration(choice = E.A)
        else -> null
    }

Json.encodeToString(workspaceConfiguration) works as expected. Yet, here’s the actual workspace/configuration response:

[{ "choice": 0 }]

It seems enum members are serialized using their ordinals rather than names. Why is this the case and what can I do so that my custom serial names are respected?

Sorry for the delay. This appears to be the behavior of the underlying lsp4j library. We need to check if it allows annotating enums in some way to achieve a different serialization.

LSP4J uses GSON, switching to GSON annotations could fix this.

If you mean com.google.gson.annotations.SerializedName, that doesn’t work, unfortunately. LSP4IJ’s MessageJsonHandler has a GsonBuilder that registers EnumTypeAdapter, which only ever reads and writes integers (either from .value or the ordinal number).

The LSP API doesn’t expose these objects anywhere, as far as I’m aware. If it did, I would be able to override getDefaultGsonBuilder() to use a custom adapter.