Dev Tools · 1h ago
Gson’s silent default: why missing @SerializedName breaks your Android app
A developer removed @SerializedName("base_stat") from a Kotlin data class, causing Gson to silently default baseStat to 0 instead of parsing the JSON field. Gson matches JSON keys to property names exactly; without the annotation, the camelCase property baseStat doesn’t match snake_case base_stat. The bug compiles and runs without errors, making it a common interview trap for Android developers.
Meridian48 take
This is a classic gotcha that underscores why annotations like @SerializedName are essential, not optional—and why Gson’s lenient defaults can hide bugs until runtime.
gsonkotlin