Upgrading to Moshi
summary
Moshi bills itself as Gson 3 and claims a smaller, safer replacement: it uses Okio to share buffer segments and cut method count roughly in half (binary ~188 KB for Gson vs smaller Moshi footprint), adds an options-based streaming API to avoid string allocations, and provides setFailOnUnknown to surface unexpected fields. It throws JSON data exceptions for unknown enum values, offers a Kotlin JsonAdapter that preserves defaults and nullability rules, and integrates with Retrofit and AutoValue.
AI-written summary · about
chapters (17)
- 0:00Intro
- 3:02Why update from Gson?
- 9:08Moshi optimizations
- 11:30FieldNaming Policy
- 12:42Reflective field renaming
- 15:09Streaming API
- 15:52JsonReader Options
- 16:35setFailOnUnknown
- 21:58Object Mapping without Footgun
- 26:43Object Mapping Unknown Enums
- 29:37Object Mapping with JsonQualifiers
- 34:21Even Easier JsonAdapters
- 35:58Polymorphic Types
- 41:40Retrofit
- 43:11Auto-Value-Moshi
- 44:40KotlinsonAdapter
- 48:07Resources
related talks
32mUpgrading to Moshi
44mwhat you didn’t know about retrofit with kotlin
40mThe Life-Changing Magic of Kotlin Multiplatform Serialization
40m640K ought to be enough for anyone
38mProtobuf for speeding up your Android application
09mCollaborating with Protobuf & Type-Safe APIs
39mKotlin, Practically Speaking
38mEverybody Hates Nougat
