You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(dart): Fix decoding of repeated double fields. (#3166)
1. Replace having a bespoke `repeated` deserializer per primitive type,
e.g. `decodeListBytes` with a list comprehension using the primitive
decoder , e.g.
`decodeBytes`.
So the generated code looks like:
```dart
switch (json['foo')) {
null => [],
List<Object?> $1 => [for (final i in $1) decodeBytes(i)],
_ => throw FormatException('"foo" is not a list')
}
```
2. Do the same with `map` except use a map comprehension and decode both
the key and value (I think that key decoding is incorrect because
non-string keys are supported by proto - but that issue existed
previously as well)
3. Expect that all decoders, e.g. `decodeBytes` return the correct type
and that is not nullable. That means that the `null` guards have to be
placed in the generated code. But it also means `!` isn't needed in the
above list/map comprehensions.
```diff
- decodeBytes(json['bytes']) ?? Uint8List(0)
+ switch (json['bytes']) { null => Uint8List(0), Object $1 => decodeBytes($1)}
```
4. Change the signature of all decoders to be `Object?` so that we don't
rely on `dynamic` to allow calls to succeed, e.g.
```diff
- factory MyEnum.fromJson(String json) => MyEnum(json);
+ factory MyEnum.fromJson(Object? json) => MyEnum(json as String);
```
5. Remove `// ignore_for_file: argument_type_not_assignable` from
generated code because it is no longer needed after 1-4.
"switch (json['boolList']) { null => [], List<Object?> $1 => [for (final i in $1) decodeBool(i)], _ => throw FormatException('\"boolList\" is not a list') }",
"switch (json['bytesList']) { null => [], List<Object?> $1 => [for (final i in $1) decodeBytes(i)], _ => throw FormatException('\"bytesList\" is not a list') }",
"switch (json['doubleList']) { null => [], List<Object?> $1 => [for (final i in $1) decodeDouble(i)], _ => throw FormatException('\"doubleList\" is not a list') }",
"switch (json['fixed32List']) { null => [], List<Object?> $1 => [for (final i in $1) decodeInt(i)], _ => throw FormatException('\"fixed32List\" is not a list') }",
"switch (json['int32List']) { null => [], List<Object?> $1 => [for (final i in $1) decodeInt(i)], _ => throw FormatException('\"int32List\" is not a list') }",
"switch (json['stringList']) { null => [], List<Object?> $1 => [for (final i in $1) decodeString(i)], _ => throw FormatException('\"stringList\" is not a list') }",
"switch (json['int32List']) { null => [], List<Object?> $1 => [for (final i in $1) decodeInt(i)], _ => throw FormatException('\"int32List\" is not a list') }",
0 commit comments