toJson method
Converts a String representation of ObjectId
to an ObjectId
.
If the object
string is empty, null is returned. Otherwise, attempts to parse the string
into an ObjectId
using ObjectId.tryParse
. If parsing fails, null is returned.
object
is the String representation of the ObjectId
to be converted.
Returns an ObjectId
or null if the string is empty or parsing fails.
Implementation
@override
ObjectId? toJson(String object) {
return object.isEmpty ? null : ObjectId.tryParse(object);
}