json_serializable.dart
json_serializable.dart copied to clipboard
Either support converting to converter arg types or explicitly disallow non-JSON argument types
See https://github.com/google/json_serializable.dart/issues/795
Converter takes type of List<String>.
generates
LoginState _$LoginStateFromJson(Map<String, dynamic> json) {
return LoginState(
cookies:
const _CookiesJsonConverter().fromJson(json['cookies'] as List<String>),
);
}
Of course the as List<String> will fail always.
We could/should do better here!
Annoying, but this is not a blocker. User can just change the converter to do the right thing.
@kevmoo, can you provide guidance to where this code be fixed? Below is what is generated for me, but if I manually fix the code to "AppNodesJsonConverter().fromJson((json['childNodes'] ?? [])as List)" seems to fix the issue:
_$_Node _$_$_NodeFromJson(Map<String, dynamic> json) {
return _$_Node(
json['name'] as String,
childNodes:
const AppNodesJsonConverter().fromJson(json['childNodes'] as List) ??
[],
);
}
It's a bit gnarly. I'll have to dig in there!
sadly, I'm blocked by another issue - https://github.com/dart-lang/sdk/issues/45127