The goal is to serialize almost everything you ever need! json_serializable is an amazing package to serialize classes but cannot serialize complex types. This package provides convertors for these types. Check the supported types to know more.

Supported types

Type Support Type Support
Color MaterialColor
Offset Size
Directory File
DateTime IconData
Duration UuidValue

How it works

Code Json

How to use?


osum_serializable depends on build_runner and json_serializable to building the toJson and fromJson implementations. To install run these commands in your terminal.

flutter pub add --dev build_runner
flutter pub add --dev json_serializable
flutter pub add osum_serializable


To use the convertors, simply postfix the data type name with Convertor and call the annotation.

final {DATATYPE} variable;

For example, serializing IconData can be done like this.

final IconData variable;


Refer the example section for the full code.

// imports ...
part 'test.g.dart';

class Example {
  const Example(this.directory, this.file, this.color, this.duration, this.materialColor);

  factory Example.fromJson(Json json) => _$ExampleFromJson(json);

  @DirectoryConverter() // <- Convertors provided by osum_serializable!
  final Directory directory;

  final MaterialColor materialColor;

  final File file;

  final Color color;

  final Duration duration;

  Json toJson() => _$ExampleToJson(this);

Finally, don't forget to call the build_runner to generate the json implementation.

flutter pub run build_runner build