Skip to content

@JsonKey on derived attributes #1437

@Salvatore95

Description

@Salvatore95

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions