I have a model as shown below.
@JsonSerializable()
class Vehicle{
final String name;
final String make;
final String model;
final int year;
final int tires;
final int seats;
Vehicle({
this.name,
this.make,
this.model,
this.year,
this.tires,
this.seats
});
factory Vehicle.fromJson(Map<String, dynamic> json, int vehicleOwnerId) {
var response = _$VehicleFromJson(json);
response.vehicleOwnerId = vehicleOwnerId;
return response;
}
Map<String, dynamic> toJson() => _$VehicleToJson(this);
}
In another part of the application, I need to send the Vehicle object to and API end point, like this.
Future<int> sendData({Vehicle vehicle}){
final Response response = await put(
Uri.https(apiEndpoint, {"auth": authKey}),
headers: headers,
body: vehicle);
return response.statusCode;
}
Vehicle car;
// remove/exclude unwanted fields
This is where I need to remove/exclude the additional fields such as seats and tires from the Car object.
int responseCode = await sendData(vehicle: car);
I'm using Json Serializable package for handling JSON data and so it would be great if I could use JsonKey(ignore: true) to exclude the unwanted fields from a separate class which is extending the model. I'm not sure if there is any other way to do it. Can someone please help me with this situation here? Thanks in advance!