Fix Kotlin null assertion errors in Jackson by enabling NullIsSameAsDefault
Developers using Jackson to deserialize Kotlin data classes with empty lists may encounter unexpected null assertion errors. The issue arises when a field like a List is annotated with a default empty value but the incoming payload contains an empty list, causing Jackson to treat it as null. A reliable fix in Jackson 2.17 involves manually building the KotlinModule with the NullIsSameAsDefault feature enabled, rather than using the standard registerKotlinModule() shortcut. This configuration ensures that null values from the payload are treated as equivalent to the declared default, preventing runtime errors. The solution requires the jackson-module-kotlin dependency at version 2.17 or higher.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in