Skip to content

Commit

Permalink
fix Either deserialization failing when inside a collection (#97) (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelbaldi authored Jun 22, 2022
1 parent 6e6ea5a commit 28e91c0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class UnionTypeDeserializer<T>(
"unexpected deserializer not found"
}
val value = elementDeserializer.deserialize(javaType, parser.nextToken(), parser, ctxt)
parser.nextToken()
injectField.point(value)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import arrow.core.test.generators.either
import arrow.core.test.generators.option
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
import io.kotest.assertions.throwables.shouldNotThrowAny
import io.kotest.core.spec.style.FunSpec
Expand All @@ -20,6 +21,7 @@ import io.kotest.property.arbitrary.az
import io.kotest.property.arbitrary.boolean
import io.kotest.property.arbitrary.filter
import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.list
import io.kotest.property.arbitrary.orNull
import io.kotest.property.arbitrary.pair
import io.kotest.property.arbitrary.string
Expand Down Expand Up @@ -97,6 +99,18 @@ class EitherModuleTest : FunSpec() {
deserialized shouldBe original
}
}

test("should round-trip when inside a collection") {
val mapper = ObjectMapper().registerArrowModule()
checkAll(Arb.list(Arb.either(Arb.int(1..10), Arb.string(5)))) {
original: List<Either<Int, String>> ->
val serialized: String = mapper.writeValueAsString(original)
val deserialized = shouldNotThrowAny {
mapper.readValue<List<Either<Int, String>>>(serialized)
}
deserialized shouldBe original
}
}
}
}

Expand Down

0 comments on commit 28e91c0

Please sign in to comment.