@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: StringAll lessons in this course
- @Serializable Data Models
- @SerialName & Custom Field Mapping
- Nullable, Default & Optional Fields
- Plug Serialization into Ktor