Every mobile app turns text from a server into objects it can work with. The library that does this sits on every request the app makes. Most teams chose theirs years ago and have not looked at it since.
Read the Vendor's Own Warning
Gson is one of the most widely used of these libraries on Android. Its own documentation says: "Gson's main focus is on Java. Using it with other JVM languages such as Kotlin or Scala might work fine in many cases, but language-specific features such as Kotlin's non-`null` types or constructors with default arguments are not supported. This can lead to confusing and incorrect behavior" (Gson).
Translate that for a non-engineer. The app's code promises that a customer record always has an email. The parser does not know about the promise and can hand over a record without one. The failure appears later, somewhere unrelated, and takes a day to trace back.
Fail at the Door
The alternative built for the language behaves differently, and the difference is where the failure lands. Its guide states: "An object can be deserialized only when all its properties are present in the input" (kotlinx.serialization). A bad response is rejected the moment it arrives, with an error that names the missing field.
We corrected our own article on this. It used to say problems were caught before the app was even built. They are not. They are caught when the data arrives, which is still far better than three screens later, and it means tests against real server responses remain necessary.
The Migration Trap
Our earlier advice for switching was to run both libraries side by side, one as a fallback. The networking library's source rules that out: "this converter assumes that it can handle all types" (Retrofit). Whichever is listed first takes every request, and the fallback never runs. A team following the old advice would have believed it had migrated and changed nothing.
What to Ask Your Team
- Which library parses our server responses, and does it support our language's null rules?
- When the server sends something unexpected, where does the app fail?
- Do we test against recorded real responses?
- How would we prove a migration actually took effect?
-Rocky
#SoftwareReliability #DependencyRisk #Kotlin #EngineeringDreams #StrategiaX
Originally published on ANDROID-ARCHITECT, the Android engineering blog of Strategia-X, with the setup and the migration code.
