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

**URL:** <https://platform.jetbrains.com/t/enum-members-returned-by-lspserverdescriptor-getworkspaceconfiguration-are-serialized-as-numbers/3205>\
**Category:** IntelliJ Platform\
**Tags:** lsp-api, plugin-development\
**Created:** [November 26, 2025, 9:17am UTC](https://platform.jetbrains.com/t/enum-members-returned-by-lspserverdescriptor-getworkspaceconfiguration-are-serialized-as-numbers/3205 "2025-11-26T09:17:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![insyncwithfoo](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/insyncwithfoo/32/158_2.png) [@insyncwithfoo](https://platform.jetbrains.com/u/insyncwithfoo)\
**Post date:** [November 26, 2025, 9:17am UTC](https://platform.jetbrains.com/t/enum-members-returned-by-lspserverdescriptor-getworkspaceconfiguration-are-serialized-as-numbers/3205/1 "2025-11-26T09:17:11Z")

</div>

I have a `LspServerDescriptor` whose `getWorkspaceConfiguration` looks something like this:

```kotlin
@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](https://pl.kotl.in/DC7IAorGM). Yet, here’s the actual `workspace/configuration` response:

```json
[{ "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?

---

<div class="post-metadata">

**Author:** ![alexander.doroshko](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/alexander.doroshko/32/328_2.png) [@alexander.doroshko](https://platform.jetbrains.com/u/alexander.doroshko)\
**Post date:** [February 16, 2026, 8:27am UTC](https://platform.jetbrains.com/t/enum-members-returned-by-lspserverdescriptor-getworkspaceconfiguration-are-serialized-as-numbers/3205/2 "2026-02-16T08:27:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jansorg](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/jansorg/32/52_2.png) [@jansorg](https://platform.jetbrains.com/u/jansorg)\
**Post date:** [February 16, 2026, 8:40am UTC](https://platform.jetbrains.com/t/enum-members-returned-by-lspserverdescriptor-getworkspaceconfiguration-are-serialized-as-numbers/3205/3 "2026-02-16T08:40:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![insyncwithfoo](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/insyncwithfoo/32/158_2.png) [@insyncwithfoo](https://platform.jetbrains.com/u/insyncwithfoo)\
**Post date:** [February 24, 2026, 1:02pm UTC](https://platform.jetbrains.com/t/enum-members-returned-by-lspserverdescriptor-getworkspaceconfiguration-are-serialized-as-numbers/3205/4 "2026-02-24T13:02:43Z")

</div>

If you mean `com.google.gson.annotations.SerializedName`, that doesn’t work, unfortunately. LSP4IJ’s [`MessageJsonHandler`](https://github.com/eclipse-lsp4j/lsp4j/blob/5486d6fc35c87b22afd0a241154ca27f204dd9da/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/MessageJsonHandler.java#L48) has a [`GsonBuilder`](https://github.com/eclipse-lsp4j/lsp4j/blob/5486d6fc35c87b22afd0a241154ca27f204dd9da/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/MessageJsonHandler.java#L81-L87) that registers [`EnumTypeAdapter`](https://github.com/eclipse-lsp4j/lsp4j/blob/5486d6fc35c87b22afd0a241154ca27f204dd9da/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/adapters/EnumTypeAdapter.java#L30), 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.
