-
-
Notifications
You must be signed in to change notification settings - Fork 286
Open
google/json_serializable.dart
#1532Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
This only started happening since json_serializable>=6.11.0. A whole host of warnings are now reported when running code generation. No other changes. Currently using freezed==3.2.0
Nothing breaks, the code still generates the same way, but there are now lots of warnings.
To Reproduce
Take the following:
@freezed
abstract class MyResponse with _$MyResponse {
const MyResponse._();
const factory MyResponse({
@JsonKey(name: 'docs_url')
@Default('http://localhost:8000/docs')
String docsUrl,
}) = _MyResponse;
factory MyResponse.fromJson(Map<String, dynamic> json) =>
_$MyResponseFromJson(json);
}
Then generate code:
dart run build_runner build --delete-conflicting-outputs
Will yield the following warning:
W Field `docsUrl` has conflicting `JsonKey.name` annotations:
both constructor parameter and class field have this annotation.
Using constructor parameter value.
Here is the generated code:
mixin _$MyResponse {
@JsonKey(name: 'docs_url') String get docsUrl;
/// Create a copy of MyResponse
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$MyResponseCopyWith<MyResponse> get copyWith => _$MyResponseCopyWithImpl<MyResponse>(this as MyResponse, _$identity);
/// Serializes this MyResponse to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is MyResponse&&(identical(other.docsUrl, docsUrl) || other.docsUrl == docsUrl));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,docsUrl);
@override
String toString() {
return 'MyResponse(docsUrl: $docsUrl)';
}
}This is true for other keys as well, e.g. JsonKey.includeIfNull. The new version of json_serializable is now reporting this as a warning.
Expected behavior
No warnings to be emitted.
zeshanghayoomi, kimhak-jtrb, MrJohnDev, smithereensarr, Carapacik and 33 more
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working