Easily convert common Dart data types into a json compatible ones.
This package provides a unified way to work with Dart data type serialization.
All converters implement the
JsonConverter interface which has two methods:
- toJson, which serializes the value.
- fromJson, which deserializes the value.
Each converter in this package has a nullable and non-nullable variation.
A value passed to the non-nullable converter should be also non-nullable.
The name of the nullable converter starts with
optional. It may return a
For a complete example, see
This is a standalone helper package which does not have any dependencies.
In general, put the reference to this package under dependencies in your
To use this package, import it in your code:
And use any of the currently available converters, currently featuring:
- BoolConverter, which converts a
- DateTimeConverter, which converts a
- DurationConverter, which gets a total amount of seconds from
- EnumConverter, which serializes
Enumvalue as string from it's name.
- IterableConverter, which takes the other
converteras an argument and serializes each value in the
Iterablewith that converter.
Also, you can create your own converters and use them, by implementing the
You can contibute by designing your own converters and proposing them to be added to this package. Also, any bug reports are appreciated.
Why create a package for such basic features?
Because, these features are frequently used in different projects. Thus, it is very useful and convenient to have a consistent code base between projects.