arrow-kt / arrow-integrations

Λrrow Integrations is part of Λrrow, a functional companion to Kotlin's Standard Library
http://arrow-kt.io
Other
27 stars 6 forks source link

[BUG] arrow-integrations-jackson-module EitherModule deserialization fails on collections of Either #97

Closed miguelbaldi closed 2 years ago

miguelbaldi commented 2 years ago

When you try to deserialize a collection of Eithers, the EitherModule fails with the following exception: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize [simple type, class arrow.core.Either<java.lang.String,java.lang.Integer>]. Make sure json fields are valid: [left, right].

Simple code sample demonstrating the issue:

import arrow.core.Either
import arrow.integrations.jackson.module.registerArrowModule
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import com.fasterxml.jackson.module.kotlin.registerKotlinModule

class App {
    private val objectMapper = ObjectMapper()
        .registerArrowModule()
        .registerKotlinModule()
    val demo: Unit
        get() {
            val eitherList: List<Either<String, Int>> = listOf(
                Either.Right(10),
                Either.Left("left")
            )
            val eitherListJson = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(eitherList)
            println(eitherListJson)
            val eitherListJsonResult: MutableSet<Either<String, Int>> = objectMapper.readValue(eitherListJson)
            println(eitherListJsonResult)

        }
}

fun main() {
    App().demo
}

I will submit PR. Thanks

myuwono commented 2 years ago

Fixed by #98