You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am working with lots of different data classes that need to get serialized to/from Map<String, Object>, which mostly contain serializable data types as values, but also functions and other classes that cannot and should not be converted to/from JSON-compatible types but just 'passed through' as they are (but not ignored either). Since I'm not using the resulting Map as a proper JSON, I don't want the serializer to touch any type that it does not know how to handle but not drop it during a 'serialization' round trip either. Is it possible to do something like this using json_serializable?
However this causes the build runner to fail (I assume because the resulting type is still not JSON-compatible):
[SEVERE]json_serializable:json_serializable on lib/src/some_file.dart: Could not generate `fromJson` code for `someFn`.
None of the provided `TypeHelper` instances support the defined type.
package:some_package/src/some_file.dart:44:20
╷
44 │ final SomeFnType someFn;
│ ^^^^^^
╵
Is it possible to do this using TypeHelpers? If so, is there any documentation on how to provide custom TypeHelpers?
The text was updated successfully, but these errors were encountered:
That wouldn't work since I would have to write a separate toJson for every type (and the types are usually function types so there's not much opportunity for sharing a toJson implementation). I tried passing an identity function but even that doesn't work since JsonKey(toJson: ...) only works with a dynamically typed toJson implementation, not a generically typed one and thus the generated files are full of type errors.
Is it still possible to use TypeHelpers in the current version of json_serializable? I read that JsonConverters were introduced to reduce the need for TypeHelpers, but I don't think JsonConverters or toJson work in this scenario, so any pointers to relevant documentation about TypeHelpers would be appreciated.
I am working with lots of different data classes that need to get serialized to/from
Map<String, Object>
, which mostly contain serializable data types as values, but also functions and other classes that cannot and should not be converted to/from JSON-compatible types but just 'passed through' as they are (but not ignored either). Since I'm not using the resulting Map as a proper JSON, I don't want the serializer to touch any type that it does not know how to handle but not drop it during a 'serialization' round trip either. Is it possible to do something like this using json_serializable?I tried to use the following JsonConverter:
However this causes the build runner to fail (I assume because the resulting type is still not JSON-compatible):
Is it possible to do this using TypeHelpers? If so, is there any documentation on how to provide custom TypeHelpers?
The text was updated successfully, but these errors were encountered: