json_serializable.dart icon indicating copy to clipboard operation
json_serializable.dart copied to clipboard

@JsonKey on derived attributes

Open Salvatore95 opened this issue 7 months ago • 1 comments

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?

Salvatore95 avatar Jul 19 '24 14:07 Salvatore95