wktFromJson function
Converts proto3-JSON json into a decoded WKT message map (snake_case).
resolver is the per-call Any resolver (unused by the structural WKTs,
threaded only for signature uniformity).
Implementation
Object? wktFromJson(
String typeName,
Object? json,
Map<String, String>? features, [
AnyTypeResolver? resolver,
]) {
final wrapped = _wktWrappers[typeName];
if (wrapped != null) {
if (json == null) return <String, Object?>{};
return {'value': fieldFromJson(json, wrapped, features: features)};
}
switch (typeName) {
case 'google.protobuf.Timestamp':
if (json is! String) {
throw FormatException('Timestamp must be a JSON string');
}
final ts = rfc3339ToTimestamp(json);
_checkTimestampRange(_asWktMap(ts));
return ts;
case 'google.protobuf.Duration':
if (json is! String) {
throw FormatException('Duration must be a JSON string');
}
final m = stringToDuration(json);
_checkDurationRange(m);
return m;
case 'google.protobuf.FieldMask':
if (json is! String) {
throw FormatException('FieldMask must be a JSON string');
}
return _fieldMaskFromJson(json);
case 'google.protobuf.Struct':
return _structMsgFromJson(json);
case 'google.protobuf.Value':
return _valueMsgFromJson(json);
case 'google.protobuf.ListValue':
return _listValueMsgFromJson(json);
}
return json;
}