You've set up your Retrofit interface, linked GSON, and everything looks perfect—but your app keeps returning null or crashing with a "MalformedJsonException". This is the developer's rite of passage.

The Silent Killer: @SerializedName

Pro-tip: Never trust your backend developers' naming conventions. If they change "user_id" to "userId" without telling you, your model will break. Always use @SerializedName to decouples your Kotlin property names from the JSON keys.

Safe Model Declaration data class User(
@SerializedName("id") val userId: String,
@SerializedName("full_name") val name: String
)

The Heavy Hitter: LoggingInterceptor

If you're flying blind, stop. Add HttpLoggingInterceptor to your OkHttpClient. This allows you to see the EXACT JSON string being returned in Logcat. 90% of my parsing errors were solved just by looking at the raw response.

OkHttp Debug Setup val logging = HttpLoggingInterceptor()
logging.setLevel(HttpLoggingInterceptor.Level.BODY)
val client = OkHttpClient.Builder()
.addInterceptor(logging)
.build()

Summary

Decouple with SerializedName and always, always log your network body during development. Visibility is power!