Anyone have managed to use `@JsonTypeInfo` from ja...
# multiplatform
r
Anyone have managed to use
@JsonTypeInfo
from jackson in the common source of MPP project? I have tried to create expected annotation like this:
Copy code
expect annotation class JsonTypeInfo(val use: Id, val property: String) {
    enum class Id {
        CLASS
    }
}
but
actual typealias JsonTypeInfo = com.fasterxml.jackson.annotation.JsonTypeInfo
doesn't compile (fails with the Id enum class)
For the record, I've managed to make it work like this: common:
Copy code
expect enum class Id {
    CLASS
}

expect enum class As {
    PROPERTY
}

expect annotation class JsonTypeInfo(
    val use: Id,
    val include: As,
    val property: String,
    val defaultImpl: KClass<*>,
    val visible: Boolean
)

@JsonTypeInfo(Id.CLASS, As.PROPERTY, "type", JsonTypeInfo::class, false)
@Serializable
sealed class Item {
    var id: Int? = null
    var name: String? = null
}
jvm:
Copy code
actual typealias Id = com.fasterxml.jackson.annotation.JsonTypeInfo.Id

actual typealias As = <http://com.fasterxml.jackson.annotation.JsonTypeInfo.As|com.fasterxml.jackson.annotation.JsonTypeInfo.As>

actual typealias JsonTypeInfo = com.fasterxml.jackson.annotation.JsonTypeInfo
unfortunately no way to use
@OptionalExpectation
so I have to create a dummy actuals on JS target as well:
Copy code
actual enum class Id {
    CLASS
}

actual enum class As {
    PROPERTY
}

actual annotation class JsonTypeInfo(actual val use: Id, actual val include: As, actual val property: String, actual val defaultImpl: KClass<*>, actual val visible: Boolean)
114 Views