google / google/json_serializable.dart

Inheritance Issue with Json Serializable

Open
#749 4 comments 2 reactions 0 assignees View on GitHub
Type: enhancement
Dominant language
Dart
Stars
1.6k
Forks
461
Avg merge
45m
Merged PRs (30d)
1

Description

/////////////////////////////////////////////////////////////////////////////
"This is the implementation of my classes"

@JsonSerializable()
class BodyGroup{

final Map parts;

BodyGroup(this.parts){
debugPrint("Constructor called and initialized!:"+parts.toString());
}

//Abstract function
Map tabMap(){
return {};
}

void incrementTabMap(Map tabMap){
tabMap.forEach((String part, double hits) {
debugPrint("TabMap:"+tabMap.toString());
debugPrint("Part:"+part);
debugPrint("Parts:"+parts.toString());
if(parts[part])
tabMap[part] = tabMap[part] + 1;
});
}

factory BodyGroup.fromJson(Map data) => _$BodyGroupFromJson(data);

Map toJson() => _$BodyGroupToJson(this);
}

@JsonSerializable()
class Shoulders extends BodyGroup{

Shoulders({bool front=false,bool rear=false}) : super({"front":front,"rear":rear});

factory Shoulders.fromJson(Map data) => _$ShouldersFromJson(data);

Map toJson() => _$ShouldersToJson(this);

@override
Map tabMap() {
return {
"front":0,
"rear":0
};
}

}

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Now when I make an object of Shoulder class and serialize it......it doesn't include the "parts" map which is initialized always in the BodyGroup Parent class....

Can you please help me out here

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.