genovich
09/07/2020, 10:18 AMEither
to json using Jackson, and I faced with issue: when I try to serialize Either
instance - everything is ok, but when I try to serialize some wrapper-class with Either
I’ve got an exception. For Gson behavior changes: it’s returning null.
println(toJson("x".right()))
// { "value" : "x" }
data class Wrapper(val value: Either<Throwable, String>)
println(toJson(Wrapper("x".right())))
// java.lang.RuntimeException: com.fasterxml.jackson.databind.JsonMappingException: Index: 0 (through reference chain: Test$test$Wrapper["value"])
// null (for Gson)
I’m using custom serializer which converts Either.Right
to { "value" : … }
and Either.Left
to { "error": … }
, but when I’m removing it, behavior doesn’t change.pakoito
09/07/2020, 4:04 PMgenovich
09/11/2020, 10:33 AM