Skip to content

Parsing of UShort uses incorrect ranges #611

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

Closed
sconvent opened this issue Jan 14, 2023 · 2 comments
Closed

Parsing of UShort uses incorrect ranges #611

sconvent opened this issue Jan 14, 2023 · 2 comments
Labels

Comments

@sconvent
Copy link
Contributor

Describe the bug
When trying to parse a class with a field of type UShort, the parsing fails when the value is larger than the range of a (Java) Short, but is still in the range of a UShort.

To Reproduce
Execute the following Testcase:

class TestUnsigned {

    class TestClass(@JsonProperty("id") var id: UShort) {
        // Empty constructor
        constructor() : this(1u)
    }

    // Value fits into UShort, but not (Java) Short
    private val jsonData = """
        {
            "id": 50000
        }
        """

    @Test
    fun testJsonParsing() {
        val mapper = jacksonObjectMapper()
        // This will fail:
        val dataClassInstance = mapper.readValue<TestClass>(jsonData)
    }
}

The exception is:
com.fasterxml.jackson.databind.JsonMappingException: Numeric value (50000) out of range of Java short

Expected behavior
This works without exception and the value is parsed properly

Versions
Kotlin: 1.5.32
Jackson-module-kotlin: 2.15.0 (snapshot)
Jackson-databind: not sure, probably 2.15.0 as well

Additional context
This testcase still seems to work:
https://github.com/FasterXML/jackson-module-kotlin/blob/2.15/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/UnsignedNumbersTests.kt#L36-L40
So maybe the issue does not exist for UShort in general but rather when they're embedded as fields into a class.

@sconvent sconvent added the bug label Jan 14, 2023
@sconvent
Copy link
Contributor Author

I will post a PR to add the failing testcase soon.

@k163377
Copy link
Contributor

k163377 commented Mar 18, 2023

This issue is closed as the issue regarding deserialization support for value class related content will be summarized in #650.

@k163377 k163377 closed this as completed Mar 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants