This is my class:
@JsonSerializable()
class Foo {
final int a = 0;
int get b => 42;
}
The generated code doesn't include any of the a or b field:
Foo _$FooFromJson(Map<String, dynamic> json) => Foo();
Map<String, dynamic> _$FooToJson(Foo instance) => <String, dynamic>{};
Note: Please don't write solutions for doing something like Foo(this.a) or Foo() : a = 0 etc. I need to keep my structure as it is.
I think since
ais final, it is considered a constant and not variable andbis a getter and not a variable, there are no variables (fields) forjson_serializableto generate code for.You need to add a default constructor before
json_serializablecan run. Since you have no fields, you wil have an empty constructor and empty methods generated.