dkandalov/live-plugin

Kotlin Plugin: using kotlinx.serialization with Serializable

ssproessig-thales opened this issue · 0 comments

I'm having a JSON file

{
    "version": "2.1.0",
    "runs": [
        {
            "tool": {
                "driver": {
                    "name": "lint4jsondb / PC-lint plus",
                    "semanticVersion": "1.0.0"
                }
            },
            "results": []
        }
    ]
}

and a plugin PoC like this

import liveplugin.*
import java.io.File
import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json


@Serializable
data class SarifReport(
    val version: String
)


registerAction("Show SARIF report", keyStroke="ctrl alt shift 0") {
    val jsonString: String = File("report.sarif").readText(Charsets.UTF_8)

    try {
        val o = Json.decodeFromString<SarifReport>(jsonString);
        show(o)
    }
    catch (e:Exception) {
        show(e)
    }
}

This leads to CLion showing

kotlinx.serialization.SerializationException: Serializer for class 'SarifReport' is not found.Mark the class as @Serializable or provide the serializer explicitly. at 
kotlinx.serialization.internal.Platform_commonKt.serializerNotRegistered(Platform.common.kt:91) at 
kotlinx.serialization.internal.PlatformKt.platformSpecificSerializerNotRegistered(Platform.kt:29) at 
kotlinx.serialization.SerializersKt__SerializersKt.serializer(Serializers.kt:60) at 
kotlinx.serialization.SerializersKt.serializer(Unknown Source) at Plugin$1.invoke(plugin.kts:25) at Plugin$1.invoke(plugin.kts:5) at liveplugin.ActionsKt$AnAction$1.actionPerformed(actions.kt:132) at 
com.intellij.openapi.actionSystem.ex.ActionUtil.doPerformActionOrShowPopup(ActionUtil.java:323) at 
com.intellij.openapi.keymap.impl.ActionProcessor.performAction(ActionProcessor.java:47) at 
com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher$1.performAction(IdeKeyEventDispatcher.java:584) at 
com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.lambda$doPerformActionInner$9(IdeKeyEventDispatcher.java:706) at 
com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:105) at 
com.intellij.openapi.application.TransactionGuardImpl.performUserActivity(TransactionGuardImpl.java:94) at 
com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.lambda$doPerformActionInner$10(IdeKeyEventDispatcher.java:706) at 
com.intellij.openapi.actionSystem.ex.ActionUtil.performDumbAwareWithCallbacks(ActionUtil.java:346) at 
com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.doPerformActionInner(IdeKeyEventDispatcher.java:703) at 
com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.java:647) at 
com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.java:595) at 
com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processActionOrWaitSecondStroke(IdeKeyEventDispatcher.java:478) at 
com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.inInitState(IdeKeyEventDispatcher.java:467) at 
com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.dispatchKeyEvent(IdeKeyEventDispatcher.java:225) at 
com.intellij.ide.IdeEventQueue.dispatchKeyEvent(IdeEventQueue.java:815) at 
com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:750) at 
com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$5(IdeEventQueue.java:437) at 
com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:772) at 
com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$6(IdeEventQueue.java:436) at 
com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:113) at 
com.intellij.ide.IdeEventQueue.performActivity(IdeEventQueue.java:615) at 
com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$7(IdeEventQueue.java:434) at 
com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:813) at 
com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:480) at 
java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207) at 
java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128) at 
java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117) at 
java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113) at 
java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105) at 
java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)

which somehow shows that the "generation part" of Kotlin Serialization is not executed for the @Serializable annotation - hence not creating the serializer().

Any idea how I can achieve this? Thank you!