Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question/Feature] how set converter globally and override builtin #1272

Open
gemunet opened this issue Jan 26, 2023 · 4 comments
Open

[Question/Feature] how set converter globally and override builtin #1272

gemunet opened this issue Jan 26, 2023 · 4 comments

Comments

@gemunet
Copy link

gemunet commented Jan 26, 2023

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

@Ali1Ammar
Copy link

i also need this feature to convert all datetime to local time

@kevmoo
Copy link
Collaborator

kevmoo commented Feb 6, 2023

there is not an easy way to do this, sadly. At least not yet. Will flag this as a feature request.

@shilangyu
Copy link

shilangyu commented May 16, 2023

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

@Nico04
Copy link

Nico04 commented Aug 4, 2023

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 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants