toJson method
Converts the CustomerAttributes object to a JSON map.
This method merges additionalAttributes at the top level of the JSON, similar to the Android implementation's MapFromCustomerAttributes. Null values are automatically removed from the final JSON output.
Implementation
Map<String, dynamic> toJson() {
// Start with the standard serialized fields
final json = _$CustomerAttributesToJson(this);
// Merge additionalAttributes at the top level
if (additionalAttributes != null) {
json.addAll(additionalAttributes!);
}
// Remove null values before sending
json.removeWhere((key, value) => value == null);
return json;
}