diff --git a/CHANGELOG.md b/CHANGELOG.md index e8dc3d5d..6d893552 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## v4.4.3 +- Fixed a bug that `TweetEditControls.remainingCount` had a different type. ([#571](https://github.com/twitter-dart/twitter-api-v2/issues/571)) - Fixed to exclude null fields when performing `toJson` on `TwitterResponse` and other model objects. With this fix, the JSON obtained from `toJson` is now fully equivalent to the raw JSON returned by Twitter. ([#569](https://github.com/twitter-dart/twitter-api-v2/issues/569)) ## v4.4.2 diff --git a/lib/src/service/tweets/tweet_edit_controls.dart b/lib/src/service/tweets/tweet_edit_controls.dart index e6c8eba3..b41f6bc1 100644 --- a/lib/src/service/tweets/tweet_edit_controls.dart +++ b/lib/src/service/tweets/tweet_edit_controls.dart @@ -21,9 +21,7 @@ class TweetEditControls with _$TweetEditControls { /// A number indicating how many more tweets will be allowed to be edited. /// /// Tweet can be edited up to 5 times. - @JsonKey(name: 'edits_remaining') - @_RemainingCountConverter() - required int remainingCount, + @JsonKey(name: 'edits_remaining') required int remainingCount, /// Indicates when the permission to edit tweets will expire. @JsonKey(name: 'editable_until') required DateTime expireAt, @@ -32,14 +30,3 @@ class TweetEditControls with _$TweetEditControls { factory TweetEditControls.fromJson(Map json) => _$TweetEditControlsFromJson(json); } - -class _RemainingCountConverter implements JsonConverter { - /// Returns the new instance of [_RemainingCountConverter]. - const _RemainingCountConverter(); - - @override - int fromJson(String value) => int.parse(value); - - @override - String toJson(int value) => value.toString(); -} diff --git a/lib/src/service/tweets/tweet_edit_controls.freezed.dart b/lib/src/service/tweets/tweet_edit_controls.freezed.dart index 89a89fda..ab21f4ee 100644 --- a/lib/src/service/tweets/tweet_edit_controls.freezed.dart +++ b/lib/src/service/tweets/tweet_edit_controls.freezed.dart @@ -30,7 +30,6 @@ mixin _$TweetEditControls { /// /// Tweet can be edited up to 5 times. @JsonKey(name: 'edits_remaining') - @_RemainingCountConverter() int get remainingCount => throw _privateConstructorUsedError; /// Indicates when the permission to edit tweets will expire. @@ -49,13 +48,9 @@ abstract class $TweetEditControlsCopyWith<$Res> { TweetEditControls value, $Res Function(TweetEditControls) then) = _$TweetEditControlsCopyWithImpl<$Res>; $Res call( - {@JsonKey(name: 'is_edit_eligible') - bool isEditable, - @JsonKey(name: 'edits_remaining') - @_RemainingCountConverter() - int remainingCount, - @JsonKey(name: 'editable_until') - DateTime expireAt}); + {@JsonKey(name: 'is_edit_eligible') bool isEditable, + @JsonKey(name: 'edits_remaining') int remainingCount, + @JsonKey(name: 'editable_until') DateTime expireAt}); } /// @nodoc @@ -98,13 +93,9 @@ abstract class _$$_TweetEditControlsCopyWith<$Res> __$$_TweetEditControlsCopyWithImpl<$Res>; @override $Res call( - {@JsonKey(name: 'is_edit_eligible') - bool isEditable, - @JsonKey(name: 'edits_remaining') - @_RemainingCountConverter() - int remainingCount, - @JsonKey(name: 'editable_until') - DateTime expireAt}); + {@JsonKey(name: 'is_edit_eligible') bool isEditable, + @JsonKey(name: 'edits_remaining') int remainingCount, + @JsonKey(name: 'editable_until') DateTime expireAt}); } /// @nodoc @@ -145,13 +136,9 @@ class __$$_TweetEditControlsCopyWithImpl<$Res> @JsonSerializable() class _$_TweetEditControls implements _TweetEditControls { const _$_TweetEditControls( - {@JsonKey(name: 'is_edit_eligible') - required this.isEditable, - @JsonKey(name: 'edits_remaining') - @_RemainingCountConverter() - required this.remainingCount, - @JsonKey(name: 'editable_until') - required this.expireAt}); + {@JsonKey(name: 'is_edit_eligible') required this.isEditable, + @JsonKey(name: 'edits_remaining') required this.remainingCount, + @JsonKey(name: 'editable_until') required this.expireAt}); factory _$_TweetEditControls.fromJson(Map json) => _$$_TweetEditControlsFromJson(json); @@ -168,7 +155,6 @@ class _$_TweetEditControls implements _TweetEditControls { /// Tweet can be edited up to 5 times. @override @JsonKey(name: 'edits_remaining') - @_RemainingCountConverter() final int remainingCount; /// Indicates when the permission to edit tweets will expire. @@ -217,13 +203,10 @@ class _$_TweetEditControls implements _TweetEditControls { abstract class _TweetEditControls implements TweetEditControls { const factory _TweetEditControls( - {@JsonKey(name: 'is_edit_eligible') - required final bool isEditable, - @JsonKey(name: 'edits_remaining') - @_RemainingCountConverter() - required final int remainingCount, - @JsonKey(name: 'editable_until') - required final DateTime expireAt}) = _$_TweetEditControls; + {@JsonKey(name: 'is_edit_eligible') required final bool isEditable, + @JsonKey(name: 'edits_remaining') required final int remainingCount, + @JsonKey(name: 'editable_until') required final DateTime expireAt}) = + _$_TweetEditControls; factory _TweetEditControls.fromJson(Map json) = _$_TweetEditControls.fromJson; @@ -241,7 +224,6 @@ abstract class _TweetEditControls implements TweetEditControls { /// /// Tweet can be edited up to 5 times. @JsonKey(name: 'edits_remaining') - @_RemainingCountConverter() int get remainingCount; @override diff --git a/lib/src/service/tweets/tweet_edit_controls.g.dart b/lib/src/service/tweets/tweet_edit_controls.g.dart index c68e09ba..b02076c2 100644 --- a/lib/src/service/tweets/tweet_edit_controls.g.dart +++ b/lib/src/service/tweets/tweet_edit_controls.g.dart @@ -14,8 +14,7 @@ _$_TweetEditControls _$$_TweetEditControlsFromJson(Map json) => $checkedCreate( ($checkedConvert) { final val = _$_TweetEditControls( isEditable: $checkedConvert('is_edit_eligible', (v) => v as bool), - remainingCount: $checkedConvert('edits_remaining', - (v) => const _RemainingCountConverter().fromJson(v as String)), + remainingCount: $checkedConvert('edits_remaining', (v) => v as int), expireAt: $checkedConvert( 'editable_until', (v) => DateTime.parse(v as String)), ); @@ -32,7 +31,6 @@ Map _$$_TweetEditControlsToJson( _$_TweetEditControls instance) => { 'is_edit_eligible': instance.isEditable, - 'edits_remaining': - const _RemainingCountConverter().toJson(instance.remainingCount), + 'edits_remaining': instance.remainingCount, 'editable_until': instance.expireAt.toIso8601String(), }; diff --git a/test/src/service/tweets/data/lookup_by_id.json b/test/src/service/tweets/data/lookup_by_id.json index 762d69e6..d085e5b7 100644 --- a/test/src/service/tweets/data/lookup_by_id.json +++ b/test/src/service/tweets/data/lookup_by_id.json @@ -5,7 +5,7 @@ "edit_controls": { "is_edit_eligible": true, "editable_until": "2022-08-21 09:35:20.311", - "edits_remaining": "4" + "edits_remaining": 4 } } } \ No newline at end of file diff --git a/test/src/service/tweets/tweets_service_test.dart b/test/src/service/tweets/tweets_service_test.dart index 70ee7dde..1c9b6649 100644 --- a/test/src/service/tweets/tweets_service_test.dart +++ b/test/src/service/tweets/tweets_service_test.dart @@ -1615,7 +1615,7 @@ void main() { expect(editControls.toJson(), { 'is_edit_eligible': true, - 'edits_remaining': '4', + 'edits_remaining': 4, 'editable_until': '2022-08-21T09:35:20.311' }); });