toJson method

dynamic toJson()

Serializes the field value to JSON format.

The default implementation returns rawValue directly. Subclasses may override this to provide custom serialization logic (e.g., formatting dates, converting types).

Returns: The JSON-serializable representation of the field value. Returns null if rawValue is null, allowing JSON to omit the field when appropriate.

Example:

final field = JsonString('name');
print(field.toJson()); // null

field.value = 'John';
print(field.toJson()); // 'John'

Implementation

dynamic toJson() {
  return rawValue;
}