The backend team made what looked like a safe change: a new order status, "partially_refunded". The web app picked it up the same day. The current mobile release handled it fine. But a version from eight months ago, still on a few percent of devices, started failing to load the order list for anyone who had one of those orders. The API hadn't removed or renamed anything.

A web frontend updates the moment you deploy it. A mobile app doesn't. Old versions stay installed for months or years, and they parse your responses with whatever rules they were built with. Here's what usually breaks them and how to change an API without finding out from crash reports.

What breaks old clients

Most of these come from the JSON decoder, not your own code:

  • A new enum value. Swift's Codable throws when a raw value isn't one of the enum's cases. Moshi throws on unknown enum values by default too. Gson tends to set the field to null instead, which in Kotlin can put a null into a property declared non-null and fail later, somewhere unrelated.
  • A field that becomes null or goes missing. If the model declares it non-optional, decoding fails with an error like keyNotFound or valueNotFound in Swift, or a missing-field exception in kotlinx.serialization.
  • A changed type. An id that was a number and is now a string, or a price that moves from a number to an object. Old decoders fail with a type mismatch.
  • One bad item fails the whole list. With a plain [Order] or List<Order>, one order the old model can't decode usually fails the entire response, so the user sees an empty or error screen, not one missing row. That's why only users with a "partially refunded" order were affected.
  • New keys, depending on the library. Swift's Codable, Moshi and Gson ignore keys they don't know. kotlinx.serialization does not by default: unless ignoreUnknownKeys = true is set, any new field in a response throws. This one catches teams that switched libraries.

Make the client tolerant

Changes in the app protect future versions, so do them before you need them:

  • Unknown enum values map to a fallback. In Swift, decode the raw string and fall back to an .unknown case in a custom init(from:). In Moshi, EnumJsonAdapter.create(...).withUnknownFallback(...) from moshi-adapters. In kotlinx.serialization, coerceInputValues = true can replace an unknown enum value with the property's default, if it has one (check the behavior for your version). Then make the UI show something neutral for .unknown.
  • Ignore unknown keys everywhere. For kotlinx.serialization, set ignoreUnknownKeys = true on the shared Json instance.
  • Decode lists item by item where one bad item shouldn't hide the rest: decode each element separately, drop (and log) the ones that fail.
  • Make fields optional when the app can work without them, and give defaults rather than crashing.
  • Log decoding failures with the endpoint and field path so a schema problem shows up as a clear report, not a generic "something went wrong".

Make the server careful

The server can't fix installed apps, so it has to change in ways old apps survive:

  • Add, don't change. New fields are usually safe. Renaming, removing or changing the type of a field is a breaking change for every old version that reads it.
  • Know which versions are still calling. Send the app version and build number on every request (in the User-Agent or a dedicated header) and log it. Before removing a field or changing an enum, check how much traffic still comes from versions that depend on it.
  • Version per client when needed. If a change can't be additive, serve the old shape to old versions (based on that header, or a versioned path) until their share is small enough to drop.
  • Gate new enum values. A new status can be sent only to app versions that know it, with older versions getting the closest existing value.

A way to force an update

At some point the oldest versions have to go. Plan for it before you need it:

  • A minimum-version check: the app asks a config endpoint (or reads a header on every response) for the minimum supported version, and shows a blocking "please update" screen below it. This has to be in the app already. You can't add it to versions that are installed.
  • On Android, the Play In-App Updates API can show an immediate or flexible update flow. On iOS there's no built-in equivalent, so most apps show their own screen with a link to the App Store page.
  • Use it rarely. A forced update annoys users and doesn't help people with no connection or an old OS the new version doesn't support.

Testing it

  • Decoder tests with hostile JSON: an extra key, an unknown enum value, a null in each field, and a list where one item is malformed. Each should produce a usable result, not a thrown error.
  • Run an old build against staging before shipping a backend change. Keep the last few release builds installable for this.
  • Replay recorded responses. Save real responses from the current API and decode them with the models from older releases in CI.
  • Watch the response, not just the code. Before a schema change, capture what the server actually sends today. Fields the docs say are never null sometimes are.

This article was created with the help of AI.