encodeForProtocol static method
Encode the provided object to a Json-formatted String.
if object implements ProtocolSerialization interface then
toJsonForProtocol it will be used instead of toJson method
Implementation
static String encodeForProtocol(
Object? object, {
bool formatted = false,
}) {
/// Added this check to avoid the multiple if-else conditions inside the encode method
/// If the object implements ProtocolSerialization, directly use toJsonForProtocol.
if (object is ProtocolSerialization) {
return encode(
object.toJsonForProtocol(),
formatted: formatted,
encodeForProtocol: true,
);
}
return encode(
object,
formatted: formatted,
encodeForProtocol: true,
);
}