小编Boh*_*nko的帖子

如何使用 kotlinx 序列化通过 open val 序列化 kotlin 密封类

import kotlinx.serialization.Serializable

@Serializable
sealed class Exercise(open val id: String) {

    @Serializable
    data class Theory(override val id: String) : Exercise(id)
}
Run Code Online (Sandbox Code Playgroud)

我的代码中有这样的密封类,编译器告诉我: Serializable class has duplicate serial name of property 'id', either in the class itself or its supertypes

有没有办法在可序列化的密封类中拥有 open val,在覆盖它时可以正常工作?

serialization kotlin kotlinx.serialization

9
推荐指数
1
解决办法
8040
查看次数