Paulius Ruminas

    Paulius Ruminas

    3 years ago
    Hello, I get this error:
    e: java.lang.IllegalStateException: class NewImport has duplicate serial name of property feedId, either in it or its parents.
    when I'm annotating a sealed class with @Serializable:
    @Serializable
    sealed class FeedOperation(open val feedId: FeedId) {
    
        @Serializable
        data class NewImport(override val feedId: FeedId) : FeedOperation(feedId)
    
        @Serializable
        data class RedoImport(override val feedId: FeedId) : FeedOperation(feedId)
    
        @Serializable
        data class RemoveImported(override val feedId: FeedId) : FeedOperation(feedId)
    }
    Are there any workarounds for this?
    Dominaezzz

    Dominaezzz

    3 years ago
    Use
    abstract
    instead of
    open
    .
    Paulius Ruminas

    Paulius Ruminas

    3 years ago
    The only way it works is if I do
    @Serializable
    sealed class FeedOperation(@Transient open val feedId: FeedId = null!!)
    Dominaezzz

    Dominaezzz

    3 years ago
    Will this do?
    @Serializable
    sealed class FeedOperation {
        abstract val feedId: FeedId
    
        @Serializable
        data class NewImport(override val feedId: FeedId) : FeedOperation()
    
        @Serializable
        data class RedoImport(override val feedId: FeedId) : FeedOperation()
    
        @Serializable
        data class RemoveImported(override val feedId: FeedId) : FeedOperation()
    }
    Paulius Ruminas

    Paulius Ruminas

    3 years ago
    It works. Thank you. I didn't think about this.
    I tried doing
    @Serializable
    sealed class FeedOperation(abstract val feedId: FeedId)
    and it did not work