-
Notifications
You must be signed in to change notification settings - Fork 435
Closed
Description
Given the following class:
@JsonSerializable(createFactory: false, createToJson: true)
class SerializationTest {
SerializationTest(this.x, this.y);
final int x;
@JsonKey(includeToJson: false)
final int y;
Map<String, dynamic> toJson() => _$SerializationTestToJson(this);
}I would expect the generated serializer to only include x. However, this is the produced function:
Map<String, dynamic> _$SerializationTestToJson(SerializationTest instance) =>
<String, dynamic>{
'x': instance.x,
'y': instance.y,
};Also serializing y.
y disappears if we change the annotation to includeFromJson: false.
I believe the culprit is this line:
| bool get explicitNoToJson => includeFromJson == false; |
It should test for includeToJson == false.
Environment:
dependencies:
json_annotation: ^4.8.0
dev_dependencies:
build_runner: ^2.3.3
json_serializable: ^6.6.0$ dart --version
Dart SDK version: 2.19.0-444.2.beta (beta) (Thu Dec 15 17:12:16 2022 +0000) on "macos_arm64"