Repository: google/json_serializable.dart

Issue #496: Getter with static value is not being serialized
Created: 2019-06-01T20:14:51Z
$ flutter --version
Flutter 1.5.4-hotfix.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 7a4c33425d (5 weeks ago) • 2019-04-29 11:05:24 -0700
Engine • revision 52c7a1e849
Tools • Dart 2.3.0 (build 2.3.0-dev.0.5 a1668566e5)
I have a bunch of the models that look like this:
class SomeModel implements GeneralModel
{
  SomeModel();

  factory AuthorizationStateWaitTdlibParameters.fromJSON(String json) =>
  _$AuthorizationStateWaitTdlibParametersFromJson(jsonDecode(json));

  @override
  String toJSON() => jsonEncode(_$AuthorizationStateWaitTdlibParametersToJson(this));

  @JsonKey(name: "CONSTRUCTOR")
  @override
  int get typeID => 42; // each model has its own constant
}
When I run flutter pub run build_runner build, typeID getter is not being serialized, though I need it to be:
Map<String, dynamic> _$AuthorizationStateWaitTdlibParametersToJson(
        AuthorizationStateWaitTdlibParameters instance) =>
    <String, dynamic>{};
Is there a way to get it serialized?

Duplicate issue #701: How to generate ToJson for fields from superclass
Created: 2020-09-03T18:28:25Z
I have checked a lot of issues and I don't quite get how generator for toJson works.
My class:
part 'box_attention_data.g.dart';

@JsonSerializable()
class BoxAttentionData extends WidgetItemNestedData {
  final String text;

  BoxAttentionData({@required this.text}) : super(WidgetItemType.box_attention);

  @override
  List<Object> get props => [text];

  factory BoxAttentionData.fromJson(Map<String, dynamic> json) =>
      _$BoxAttentionDataFromJson(json);

  Map<String, dynamic> toJson() => _$BoxAttentionDataToJson(this);
}
My abstract class:
abstract class WidgetItemNestedData extends Equatable {
  final WidgetItemType type;

  WidgetItemNestedData(this.type);

  Map<String, dynamic> toJson();
}

enum WidgetItemType {
  card_contact_info,
  card_action,
  box_attention,
  list_info,
  expandable_list,
  checklist,
  empty_space,
  card_photo,
  simple_photo,
  static_simple_card,
  unknown,
}
The generated file:
part of 'box_attention_data.dart';

// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************

BoxAttentionData _$BoxAttentionDataFromJson(Map<String, dynamic> json) {
  return BoxAttentionData(
    text: json['text'] as String,
  );
}

Map<String, dynamic> _$BoxAttentionDataToJson(BoxAttentionData instance) =>
    <String, dynamic>{
      'text': instance.text,
    };

What I want in generated file is to have field type from superclass.
I have tried overriding getter and annotating it:
  @override
  @JsonKey(name: 'type')
  WidgetItemType get type => super.type;
The only thing that worked was setting it in constructor:
BoxAttentionData({@required this.text, WidgetItemType type = WidgetItemType.box_attention}) : super(type);
The problem is I don't think it is good idea to pass that in constructor (I prefer to do that in super, so nobody can setup different type than intended). Is there any other way to make it working?

Closing comment (2020-09-07T23:19:06Z): Duplicate of #496 – more or less