google / google/built_value.dart
MapJsonObject: the JsonObjectSerializer serializer is not recognized
- Dominant language
- Dart
- Stars
- 886
- Forks
- 195
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 4
Description
1. If I declare a field like: `MapJsonObject` it breaks saying:
```dart
MapJsonObject get payload;
```
Error:
```
type 'ListJsonObject' is not a subtype of type 'MapJsonObject' in type cast
```

Even If I declare the `JsonObjectSerializer` (like https://github.com/google/built_value.dart/issues/1159) like this:
```dart
import 'package:built_value/src/json_object_serializer.dart';
final Serializers serializers = (_$serializers.toBuilder()
..add(JsonObjectSerializer())
```
2. If I declare the field like `JsonObject` it does not break, and internally it contains the proper `MapJsonObject`. It seems that the way to find the proper serializer uses
# Expected
If I declare the Type like `MapJsonObject` it should work fine so everyone that use the model could know if it contains a list, a map or what.
# Investigation
- It seems that the `BuiltJsonSerializer` use only the first type to find serializers:
https://github.com/google/built_value.dart/blob/master/built_value/lib/src/built_json_serializers.dart#L53
- The `JsonObjectSerializer` contains all types here but since the other one just one the first one then it can not find the serializer for it:
https://github.com/google/built_value.dart/blob/master/built_value/lib/src/json_object_serializer.dart#L12-L19
Contributor guide
Assessment
This issue has not been assessed yet.