encodeWithTypeForProtocol method

String encodeWithTypeForProtocol(
  1. Object? object, {
  2. bool formatted = false,
})

Encode the provided object to a Json-formatted String, including the class name so that it can be decoded even if the class is unknown. If formatted is true, the output will be formatted with two spaces indentation. If object implements ProtocolSerialization interface, then toJsonForProtocol will be used instead of the toJson method.

Implementation

String encodeWithTypeForProtocol(
  Object? object, {
  bool formatted = false,
}) {
  return encode(
    wrapWithClassName(object),
    formatted: formatted,
    encodeForProtocol: true,
  );
}