google / google/built_value.dart

MapJsonObject: the JsonObjectSerializer serializer is not recognized

Open
#1,161 2 comments 0 reactions 1 assignee Claimed by @davidmorgan View on GitHub
p2 / feature request
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
```

![image](https://user-images.githubusercontent.com/76348/172961833-c2618da1-f2cc-4a33-a8e2-52ae302b05a4.png)

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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.