0PricingLogin
Kotlin Multiplatform Academy · Lesson

@SerialName & Custom Field Mapping

Match Kotlin names to mismatched JSON keys.

Names Do Not Always Match

Real APIs love keys like user_name, but Kotlin prefers userName. @SerialName lets the two disagree peacefully.

Rename a Single Field

Put @SerialName above a property to tell the serializer which JSON key it really maps to.

@SerialName("user_name") val userName: String

All lessons in this course

  1. @Serializable Data Models
  2. @SerialName & Custom Field Mapping
  3. Nullable, Default & Optional Fields
  4. Plug Serialization into Ktor
← Back to Kotlin Multiplatform Academy