toJson method
ここでの toJson とは json へ encode 可能な形式へ変換するという意味で使われる.
つまり json string を返すというわけではない.
また serialize としても利用するため deserialize 可能でなければならない.
Implementation
@override
Map<String, dynamic> toJson() {
const lessThan = '<';
final type = runtimeType.toString();
late final String head;
final index = type.indexOf(lessThan);
if (index == -1) {
head = type;
} else {
head = type.substring(0, index);
}
final edited = properties.entries.map((e) {
final value = e.value;
if (value is ToJsonSignature) return MapEntry(e.key, value.toJson());
return MapEntry(e.key, value);
});
return {
head: Map.fromEntries(edited),
};
}