messageToJson function
Converts a decoded message message (snake_case proto field names) to its
proto3-JSON value — a JSON-compatible Map<String, Object?> (camelCase
keys, defaults omitted), NOT a serialized string.
This is the object-valued sibling of marshalJson (marshalJson is exactly
jsonEncode(messageToJson(message, descriptor))). Generated model code
delegates its toProto3Json() here so the conformance-pinned runtime does
the conversion.
google.protobuf.Any fields need a type registry to resolve the embedded
message. Pass anyTypeResolver to supply one for this call only — it is
threaded through the codec internals and does not mutate the
library-global anyTypeResolver hook, so independent generated models with
different registries never stomp on each other. When omitted, the
already-installed library-global hook (if any) is used as a fallback
(preserving backward compatibility for conformance.dart and other callers
that set the global once).
Implementation
Object? messageToJson(
Map<String, Object?> message,
List<Map<String, Object?>> descriptor, {
List<Map<String, Object?>>? Function(String typeName)? anyTypeResolver,
}) {
return _marshalToMap(message, descriptor, anyTypeResolver);
}