messageFromJson function
Converts a proto3-JSON value json (a decoded Map/List/scalar, NOT a
serialized string) into a decoded message map (snake_case proto field
names).
This is the object-valued sibling of unmarshalJson (unmarshalJson first
jsonDecodes its string, then calls this). Generated model code delegates
its fromProto3Json() here.
See messageToJson for the per-call anyTypeResolver threading (no global
mutation; falls back to the library-global hook when omitted).
Implementation
Map<String, Object?> messageFromJson(
Object? json,
List<Map<String, Object?>> descriptor, {
List<Map<String, Object?>>? Function(String typeName)? anyTypeResolver,
}) {
if (json is! Map) {
throw FormatException(
'Expected a JSON object at top level, got ${json.runtimeType}',
);
}
final stringMap = <String, Object?>{};
for (final entry in json.entries) {
stringMap[entry.key.toString()] = entry.value;
}
return _unmarshalFromMap(stringMap, descriptor, anyTypeResolver);
}