Encode the provided object to a json-formatted String, include class
name so that it can be decoded even if th class is unknown.
If formatted is true, the output will be formatted with two spaces
indentation.
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.