json_serializable_converters 1.0.0 copy "json_serializable_converters: ^1.0.0" to clipboard
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:

0
likes
130
points
66
downloads

Publisher

verified publisherdogeek.me

Weekly Downloads

2024.09.20 - 2025.04.04

JsonConverters for dart core types

Repository (GitHub)
View/report issues

Topics

#json-serializable #codegen #converter

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

json_annotation

More

Packages that depend on json_serializable_converters