Map<String, Object?> toJson() { return { _typeKey: type.name, if (data != null) _dataKey: data!, }; }