Serializable PersistentStateComponent docs look to be wrong

The docs for SerializablePersistentStateComponent say you need to use @JvmField, but this does not work except for Maps and Collections: code

In order for it to work, the field needs to be marked with a storage annotation such as @field:Property instead in order to trigger this logic

3rd party plugins can also not leverage kotlin-serializazation due to different classloaders make that statement return false, is this expected and tracked as an improvement to the platform?

Hi! We are trying to resolve some complexities at the moment, at least by dropping the need for @JvmField. I don’t think kotlinx-serializazation is a right solution as it is rather bad to have JSON in XML if settings are shared in Git.

+100 on that front.

Benefits of K-S though is that it is easy to test the serialization and adding custom serialization layers if needed. Wish there was a K-S XML serializer we could use with it.

I currently test the forwards/backwards compatibility of the serialization using these utils which is close but not exact to how the IDE does the serialization, (if you have a better way please let me know):

import com.intellij.configurationStore.deserializeAndLoadState
import com.intellij.configurationStore.serializeStateInto
import com.intellij.openapi.components.PersistentStateComponent
import com.intellij.openapi.components.State
import com.intellij.openapi.util.JDOMUtil
import com.intellij.util.toByteArray
import com.intellij.util.xmlb.Constants
import org.intellij.lang.annotations.Language
import org.jdom.Element

fun PersistentStateComponent<*>.serializeState(): String {
    val holder = Element("component")
    holder.setAttribute(Constants.NAME, this.getName())
    serializeStateInto(this, holder)
    return holder.toByteArray().decodeToString()
}

private fun <T> PersistentStateComponent<T>.getName(): String {
    return this::class.annotations.filterIsInstance<State>().single().name
}

fun PersistentStateComponent<*>.deserializeState(@Language("XML") str: String) {
    deserializeAndLoadState(this, JDOMUtil.load(str))
}