json_serializable.dart
json_serializable.dart copied to clipboard
@JsonKey on derived attributes
I am trying to implement Clean Architecture by keeping Entities separate from Models but I cannot assign JsonKeys to the attributes derived from parent, below is an example of what I would like to achieve:
class Car {
final String attributeOne;
final String attributeTwo;
Car({required this.attributeOne, required this.attributeTwo})
}
@JsonSerializable()
class CarModel extends Car {
CarModel({
@JsonKey(name: 'attr_one') required String attrOne,
@JsonKey(name: 'attr_two') required String attrTwo,
}): super(attributeOne: attrOne, attributeTwo: attrTwo),
}
This approach does not work, is there any alternative way?