json_serializable_converters 1.0.0
json_serializable_converters: ^1.0.0 copied to clipboard
JsonConverters for dart core types
JsonSerializable
converters for core dart classes
Features #
- Full test coverage
- Easy to integrate
Supports:
- Bytes (
Uint8List
,List<int>
), serialized in base64 - DateTime
- Directory
- File
- Duration
- Generic Enums
- Uri
All of the converters also support a nullable()
static method to get the nullable version of that converter.
Usage #
@JsonSerializable(converters: [
BytesConverter(),
DateTimeConverter(),
DurationConverter(),
UriConverter(),
FileConverter(),
DirectoryConverter(),
EnumConverter(TestEnum.values),
])
class Model {
final DateTime dateTime;
final Duration duration;
final Uri uri;
final List<int> bytes;
final File file;
final Directory directory;
final TestEnum enumValue;
Model(this.dateTime, this.duration, this.uri, this.bytes, this.file, this.directory, this.enumValue);
factory Model.fromJson(Map<String, dynamic> json) => _$ModelFromJson(json);
Map<String, dynamic> toJson() => _$ModelToJson(this);
}
copied to clipboard
Other packages #
If you need ready-made JsonSerializable
converters for other common types, take a look at these packages: