Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Wrong Option deserialization #105

Closed
herulume opened this issue Nov 22, 2022 · 3 comments
Closed

[BUG] Wrong Option deserialization #105

herulume opened this issue Nov 22, 2022 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@herulume
Copy link

herulume commented Nov 22, 2022

Describe the bug

Option<T> de-serializes to it's internal representation (when T is present and when it's not) .

To Reproduce

Run this adapted example

import arrow.core.Option
import arrow.core.none
import arrow.core.some
import arrow.integrations.jackson.module.registerArrowModule
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe

class ExampleTest :
    FunSpec(
        {

            data class Organization(
                val name: String,
                val address: Option<String>,
                val email: Option<String>
            )

            val mapper = ObjectMapper().registerKotlinModule()
                .registerArrowModule()
                .setSerializationInclusion(
                    JsonInclude.Include.NON_ABSENT
                ) // will not serialize None as nulls

            val prettyPrinter = mapper.writerWithDefaultPrettyPrinter()

            test("example #1: data structure serialization") {
                val arrowKt = Organization("arrow-kt", none(), "foo@barr".some())

                val jsonString = prettyPrinter.writeValueAsString(arrowKt)

                jsonString shouldBe """
      {
        "name" : "arrow-kt",
        "email" : "foo@bar"
      }
    """.trimIndent()

                mapper.readValue(jsonString, Organization::class.java) shouldBe arrowKt
            }
        })

Expected behavior

  • When T is present, de-serialize to it's value.
  • When T isn't present, not show the field (according to the configuration)

Screenshots
image

Environment (please complete the following information):

Additional context
This problem appear with an Option of a value class but I was able to reproduce it with an Option<String> as per the example.

@herulume herulume added the bug Something isn't working label Nov 22, 2022
@myuwono
Copy link
Collaborator

myuwono commented Nov 24, 2022

@herulume thanks for reporting this 🙌 What was the version of arrow and arrow-integrations that were used? I struggle to replicate the problem in latest. Would you mind trying this with 0.13.3-alpha.22? Sorry about the alpha version. Arrow team is currently in the process to release this library. I'll poke the team again just to be sure.

Here is the branch with the identical test, which seemingly has the expected behaviour
https://github.com/arrow-kt/arrow-integrations/pull/106/files

@myuwono myuwono self-assigned this Nov 24, 2022
@myuwono
Copy link
Collaborator

myuwono commented Nov 25, 2022

We've just released 0.14.0 which is of the same code as 0.13.3-alpha.22. @herulume can we try against that and see if the problem persists?

@herulume
Copy link
Author

Hey!
Thank you for such a fast answer. It is indeed solved now 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants