Open
Description
UPDATE: Likely due to and blocked by dart-lang/build#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
- Use the following code
@JsonSerializable(nullable: true, includeIfNull: false)
class TestClass extends Object with _$TestClassSerializerMixin {
@JsonKey(fromJson: _colorFromJson, toJson: _colorToJson)
Color color;
TestClass();
factory TestClass.fromJson(Map<String, dynamic> 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);
- 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 #133 (comment) by @kevmoo .