Making Java enums forwards compatible
Blog post from Stainless
SDKs often face challenges with client-server version skew, particularly in Java environments like Android apps that users may not update promptly. A Java SDK for a Pet Store API faced such an issue when an API change introduced a new order status, "in_transit," causing older app versions to crash due to the `Enum.valueOf` method's inability to handle unknown enum constants. To mitigate this, a more robust solution was implemented where the SDK stores the raw API value and provides both the raw value and an enum representation, introducing a fallback case for unknown statuses. This design prevents crashes by allowing older app versions to display a generic message for new statuses and ensures that updates seamlessly incorporate new API changes without disrupting existing app functionality.