kotlin - 通过 Jackson 对 Either 进行反序列化
问题描述
我尝试通过使用 Arrow ( https://arrow-kt.io/docs/datatypes/either/ ) 中的实现或使用我自己的实现Either
在我的项目中实现。我目前面临的问题是通过杰克逊对此类进行反序列化。我尝试将注释添加到我自己的(不工作的)代码如下:
@JsonTypeInfo(use= JsonTypeInfo.Id.CLASS, include= JsonTypeInfo.As.PROPERTY, property="class")
@CordaSerializable
sealed class Either<out L, out R> {
data class Left<out L>(val a: L) : Either<L, Nothing>()
data class Right<out R>(val b: R) : Either<Nothing, R>()
val isLeft: Boolean get() = this is Left<L>
val isRight: Boolean get() = this is Right<R>
@JsonValue
fun <C> fold(ifLeft: (L) -> C, ifRight: (R) -> C): C {
when (this) {
is Left -> return ifLeft(a)
is Right -> return ifRight(b)
}
}
}
否则我也愿意在 Arrow lib 中使用 mixin,但我想我会遇到类似的问题。
提前感谢您的帮助!
解决方案
推荐阅读
- java - android java sqlite中的空指针异常
- java - android中glide的缓存时间段
- javascript - FormData 到对象的格式与节点 bodyparser 相同
- wordpress - 无法在 Elementor 中创建标题
- sql - Oracle SQL query to pivot like excel
- javascript - How to display the quantity based on the size
- optimization - How to handle equalities in optimization using ROI_solve and the alabama solver
- java - Basic Java Fundamentals
- html - How to change the Google Nexus website menu
- javascript - Is there a way to save all Javascript debugger breakpoints so that I can resume my debugging later without having to reset them?