otter_json 2.0.3

SDKdartflutter
Platformandroidioswindowslinuxmacosweb

JSON serialization with code generation. Separate generated code from source and keep everything clean.

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());

otter_json

otter_json_generator

Authors