Hi, I try to serialize `Either` to json using Jack...
# arrow
g
Hi, I try to serialize
Either
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.
Copy code
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.
p
I’d say the exceptions is in the mapper, from the info you’ve given there’s no reason why Either wouldn’t serialize correctly
g
Yeah, thanks, I found issue at GitHub https://github.com/FasterXML/jackson-databind/issues/2331