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

Usigned numbers don't serialize as expected #524

Closed
rotilho opened this issue Dec 12, 2021 · 6 comments
Closed

Usigned numbers don't serialize as expected #524

rotilho opened this issue Dec 12, 2021 · 6 comments
Assignees
Labels
bug need-test-case To work on issue, a reproduction (ideally unit test) needed
Milestone

Comments

@rotilho
Copy link

rotilho commented Dec 12, 2021

Describe the bug
Unsigned numbers inside a object serializes as signed numbers

To Reproduce
Create a data class with an ULong.MAX_VALUE field
Try to serialize it

Expected behavior
Serialize as ULong.MAX_VALUE instead of -1

Versions
Kotlin:
Jackson-module-kotlin: 2.13
Jackson-databind: 2.13

@rotilho rotilho added the bug label Dec 12, 2021
@cowtowncoder cowtowncoder added the need-test-case To work on issue, a reproduction (ideally unit test) needed label Dec 13, 2021
@cowtowncoder
Copy link
Member

Although description should be enough to reproduce the issue, adding sample test inline (or PR if preferred) could speed up resolution.

@rotilho
Copy link
Author

rotilho commented Dec 13, 2021

Sorry! Please find below:

    data class TestClass(val myNumber : ULong)
    
    @Test
    fun `test wrapped ULong`() {
        val test = TestClass(ULong.MAX_VALUE)
        val json = mapper.writeValueAsString(test)
        val deserialized = mapper.readValue<TestClass>(json)
        assertThat(deserialized, equalTo(test))
    }

Obs.: This test will also fail due to #525

@k163377
Copy link
Contributor

k163377 commented Dec 16, 2021

unsigned integers is a value class (inline class).
Therefore, it is assumed that jackson-module-kotlin does not support those cases yet.

Although serializers for unsigned integers are defined, they only apply to the following patterns that are not unboxed.
https://kotlinlang.org/docs/inline-classes.html#representation

These, along with #525, seem to be related to #199.

@k163377
Copy link
Contributor

k163377 commented Dec 18, 2021

@rotilho
I came up with a plan to improve on this problem and created a PR.
#527

@dinomite dinomite self-assigned this Dec 21, 2021
@dinomite
Copy link
Member

dinomite commented Jan 1, 2022

@rotilho I merged @k163377 's fix in #527. This should be fixed when 2.13.2 is released

@rotilho
Copy link
Author

rotilho commented Jan 5, 2022

Thank you for the work guys. Looking forward for the 2.13.2 release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug need-test-case To work on issue, a reproduction (ideally unit test) needed
Projects
None yet
Development

No branches or pull requests

4 participants