Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inheritance support - missing parent attributes #486

Closed
cybertriton opened this issue May 16, 2019 · 2 comments
Closed

inheritance support - missing parent attributes #486

cybertriton opened this issue May 16, 2019 · 2 comments

Comments

@cybertriton
Copy link

cybertriton commented May 16, 2019

File 1: a_response.dart

import 'package:json_annotation/json_annotation.dart';
part 'a_response.g.dart';
abstract class TypedResponse {
  final String objType; <-- base class has this attribute
  TypedResponse(this.objType);
}

class AResponse extends TypedResponse {
   String name;
  AResponse(this.name) : super('A'); 
  factory AResponse.fromJson(Map<String, dynamic> json) => _$AResponseFromJson(json);
  Map<String, dynamic> toJson() => _$AResponseToJson(this);
}

Generated file : a_response.g.dart:

AResponse _$AResponseFromJson(Map<String, dynamic> json) {
  return AResponse(json['name'] as String);
}

Map<String, dynamic> _$AResponseToJson(AResponse instance) {
  final val = <String, dynamic>{};
  void writeNotNull(String key, dynamic value) {
    if (value != null) {
      val[key] = value;
    }
  }
  writeNotNull('name', instance.name); <-- missing objType from base class
  return val;
}

In the pubspec.yaml, using
json_annotation: ^2.0.0

Am I missing something or is this a bug? Thanks.

@kevmoo
Copy link
Collaborator

kevmoo commented May 16, 2019

There is no constructor argument for objType, so it's not generated. This is by design.

@kevmoo kevmoo closed this as completed May 16, 2019
@kevmoo
Copy link
Collaborator

kevmoo commented May 16, 2019

Duplicate of #274

@kevmoo kevmoo marked this as a duplicate of #274 May 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants