toJson method

  1. @override
Map<String, dynamic>? toJson()
override

Serializes the nested model object to a JSON map.

Uses the model's toJson() method to serialize the nested object. Returns null if the model is null, allowing the field to be omitted from JSON output when appropriate.

Returns: A JSON map representing the serialized model object, or null if the model is null.

Example:

final field = JsonObject<AddressModel>('address');
field.value = addressModel;
print(field.toJson());
// {'street': '123 Main St', 'city': 'New York'}

Implementation

@override
Map<String, dynamic>? toJson() {
  return rawValue?.toJson();
}