How to serialize and deserialize a Dart sealed class hierarchy to and from JSON
Put a discriminator field in the JSON, switch on it in a factory on the sealed base, and switch on the subtype to write it back. Three working versions on Dart 3.13.7: hand-written pattern matching, json_serializable 6.15.2, and Freezed 4.0.3 with unionKey and fallbackUnion, plus the gotchas each one hides.