toJson method

  1. @override
num? toJson()
override

Serializes the numeric value to JSON format.

Returns the raw numeric value, which may be null if no value has been set. This allows the JSON representation to distinguish between an explicitly set 0 value and an unset (null) value.

Returns: The numeric value (int or double), or null if no value has been set.

Example:

final field = JsonNumber('count');
print(field.toJson()); // null

field.value = 42;
print(field.toJson()); // 42

Implementation

@override
num? toJson() {
  return rawValue;
}