Data Classes and Parsing Json-A Story About Converting Models to Kotlin
summary
Kitchen Stories migrates JSON models from Java POJOs to Kotlin data classes with default constructor values and non-nullable fields, reducing null-checks; parsing uses Moshi and prefers Moshi 1.6 codegen over Kotlin-reflect. Build-time adapters generate serializers, tests expose three issues: date parsing, required-field crashes (solved by a tolerant adapter that returns null or empty objects), and a Moshi bug that deserializes nulls into non-nullable lists (worked around by filtering nulls). A GitHub repo contains models, adapters and tests proving the approach.
AI-written summary · about
chapters (6)
- 0:00Introduction and motivation
- 2:51JSON parsing challenges
- 4:16Kotlin data class benefits
- 8:28JSON parsing libraries
- 11:41Handling parsing errors
- 15:39Summary and key takeaways
related talks
43mKrate ft. Moshi: a Kotlin library design case study
19mJava to Kotlin Migration Mistakes
27mkotlinx.serialization 1.0
41mAnnotation Processing in a Kotlin World
24mWhat is Kotlin Serialization, and should I use it?
15mKotlin for Test Automation
36mPerformant Multiplatform Kotlin Serialization
53mKotlin Features Guaranteed to Surprise Java Developers
