google / google/json_serializable.dart
Cannot handle types defined in Flutter dart:ui
- Dominant language
- Dart
- Stars
- 1.6k
- Forks
- 461
- Avg merge
- 45m
- Merged PRs (30d)
- 1
Description
**UPDATE**: Likely due to and blocked by https://github.com/dart-lang/build/issues/733
`Color` fields with `@JsonKey(fromJson: _colorFromJson, toJson: _colorToJson)` annotations fail.
## Setup
* json_serializable 0.5.7
* json_annotation 0.2.8
* flutter 0.4.4
## Repo
1. Use the following code
```dart
@JsonSerializable(nullable: true, includeIfNull: false)
class TestClass extends Object with _$TestClassSerializerMixin {
@JsonKey(fromJson: _colorFromJson, toJson: _colorToJson)
Color color;
TestClass();
factory TestClass.fromJson(Map jsonMap) => _$TestClassFromJson(jsonMap);
}
Color _colorFromJson(String colorString) {
int intColor = int.tryParse(colorString, radix: 16);
if (intColor == null)
return null;
else
return new Color(intColor);
}
String _colorToJson(Color color) => color.value.toRadixString(16);
```
2. Run `flutter packages pub run build_runner build`
## Result
Build fails. No usable xxx.g.dart file created. Errors on screen.
```
[SEVERE] json_serializable on lib/data/xxx.dart:
Error running JsonSerializableGenerator
At least one field has an invalid type: `color`.
package:xxxxxxxx/data/xxxx.dart:63:9
Color color;
^^^^^
```
## Comments
Seems related to functionality in https://github.com/dart-lang/json_serializable/issues/133#issuecomment-387906489 by @kevmoo .
Contributor guide
Assessment
This issue has not been assessed yet.