google / google/json_serializable.dart

Bug report - @JsonKey(includeFromJson: false) malfunctions

Open
#1,334 4 comments 1 reaction 1 assignee Claimed by @kevmoo View on GitHub
Investigation needed
Dominant language
Dart
Stars
1.6k
Forks
461
Avg merge
45m
Merged PRs (30d)
1

Description

Here's a test class

```
@JsonSerializable()
class TestClass {
TestClass({
this.a,
});

@JsonKey(includeFromJson: false)
String? a;

factory TestClass.fromJson(Map json) => _$TestClassFromJson(json);
Map toJson() => _$TestClassToJson(this);
}
```

Generated code.

```
TestClass _$TestClassFromJson(Map json) => TestClass();

Map _$TestClassToJson(TestClass instance) =>
{};
```

`TestClassToJson` should include `String a` but it doesn't. It excludes `String a` from `TestClassFromJson` and `TestClassToJson` both.

json_serializable: ^6.7.0
json_annotation: ^4.8.1

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.