@JsonKey(name: "favourite") @Default("") String favourite
In my json favourite
is rather Y
and N
, which mean true
or false
, possible to convert directly in freezed? So I can directly use boolean, instead of String
@JsonKey(name: "favourite") @Default("") String favourite
In my json favourite
is rather Y
and N
, which mean true
or false
, possible to convert directly in freezed? So I can directly use boolean, instead of String
You can create a custom converter for the field.
class MyConverter implements JsonConverter<String, bool> {
const MyConverter ();
@override
MyResponse fromJson(string input) {
switch (input) {
case "Y": return true;
case "N": return false;
default: throw NotSupportedError();
}
}
@override
String toJson(bool input) {
switch (input) {
case true: return "Y";
case false: return "N";
default: throw NotSupportedError();
}
}
}
@JsonKey(name: "favourite") @Default("") @MyConverter() String favourite