Back to feed
Dev.to
Dev.to
7/5/2026
The original title is about a Gson bug related to @SerializedName removal causing silent default values instead of errors.

The original title is about a Gson bug related to @SerializedName removal causing silent default values instead of errors.

Original: Gson silent bug that Never Said a Word(Interview Prep)

Short summary

A Gson bug occurs when @SerializedName is removed: JSON key no longer matches the Kotlin property, causing Gson to silently assign default values (0 for Int, null for String) instead of throwing an error. Gson only errors on malformed JSON or type mismatches, never missing keys. Non-null Kotlin fields imported from JSON risk delayed NullPointerException because Gson bypasses null-safety via reflection.

  • Removing @SerializedName breaks JSON-to-property name matching; Gson silently defaults missing fields to 0 or null
  • Gson throws only on malformed JSON or type mismatches, not missing keys
  • Non-null Kotlin fields can receive null from Gson reflection, violating null-safety promises and causing delayed crashes

Generated with AI, which can make mistakes.

Is this a good recommendation for you?

Comments

Failed to load comments. Please try again.

Explore more