Skip to content

Deserializing to Option[T] doesn't properly handle json string values #175

@c089

Description

@c089

I encountered an issue with deserializing JSON like this:

{"x": "42", "y": "foo"}

Note the value of x is a valid integer, but represented as a JSON string, which is fairly common. Now, trying to deserialize this to Ints works as expected: x will be parsed as Int, and y will trigger an InvalidFormatException. However, if you try to serialize this as Option[Int], it will succeed in both cases, and you get a reference to a Some that holds a String, which caused very subtle bugs in our code.

I wanted to do a pull request, but unfortunately I was not able to build this project from a clean checkout using sbt or IntelliJ, so instead I isolated some tests to an external repository. The last two tests there are failing.

If someone would be willing to help me build jackson-module-scala and/or pair with me on fixing this, jut ping me on twitter @c089.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions