json_serializable.dart
json_serializable.dart copied to clipboard
[Question/Feature] how set converter globally and override builtin
How can I set a converter globally to replace the builtin datetime for example?
this does not appear in the documentation
https://pub.dev/packages/json_serializable
replace the datetime converter with a custom one globally for all classes
i also need this feature to convert all datetime to local time
there is not an easy way to do this, sadly. At least not yet. Will flag this as a feature request.
there is not an easy way to do this, sadly. At least not yet. Will flag this as a feature request.
Don't converters solve this problem already? For example:
class MyJsonSerializable extends JsonSerializable {
const MyJsonSerializable({
super.fieldRename,
// etc., forward all props
}) : super(converters: [MyGlobalConverter()]);
}
Then just always use @MyJsonSerializable
instead of @JsonSerializable
there is not an easy way to do this, sadly. At least not yet. Will flag this as a feature request.
Don't converters solve this problem already? For example:
class MyJsonSerializable extends JsonSerializable { const MyJsonSerializable({ super.fieldRename, // etc., forward all props }) : super(converters: [MyGlobalConverter()]); }
Then just always use
@MyJsonSerializable
instead of@JsonSerializable
This is all right, but it would be even better if it was just like the in-built types like DateTime : you have nothing to specify. So for custom class on a project, you would just have to specify converter once globally, and nowhere else. That would be very handy !