Skip to content

A compile safe JSON serialization in generic way

License

Notifications You must be signed in to change notification settings

hokamc/otter_json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Otter JSON

Otter JSON

Maintenance Status

JSON serialization with code generation.

Table of Contents

Why use it

Do you suffer from json_serializable? All generated code and 'part' make your source code messy. With Otter JSON, keep everything simple and clean.

Features

  • Generated code and source code are separated
  • Easy to register new serializer
  • Support all primitives
  • Support flutter common class
  • Support List, Set, Map<String, T>
  • Support nested object

How to

  • dependencies
dependencies:
  otter_json:

dev_dependencies:
  build_runner:
  otter_json_generator:
  • annotate
@JSON
class Person {
  String firstName;
  String lastName;
}
  • generate
flutter pub run build_runner build
  • register
Otter.module(GeneratedJsonModule());
  • toJson, fromJson
Map<String, dynamic> map = Otter.toJson(Person());
Person person = Otter.fromJson({});
  • custom serializer
class ColorSerializer implements JsonSerializer<Color, int> {
  @override
  Color decode(int output) {
    return Color(output);
  }

  @override
  int encode(Color input) {
    return input.value;
  }
}

Otter.serializer(ColorSerializer());

Todo

Link

otter_json

otter_json_generator

Authors

About

A compile safe JSON serialization in generic way

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published