cereal_generator 0.0.1 cereal_generator: ^0.0.1 copied to clipboard
A serializer library for dart with no-overhead code generation.
Cereal, a serialization library for Dart #
Cereal offers no-boilerplate JSON serialization for Dart objects. It does this with Dart's new extension methods & code generation.
Example #
import 'package:cereal/cereal.dart';
part 'my_file.g.dart';
@cereal
class Struct {
final int foo;
final String bar;
Struct({this.foo, this.bar});
}
The code generator will generate a Struct.toJson
, as well as a
json.decodeStruct
method on the json
object in dart:convert
.
import 'dart:convert';
void main() {
json.encode(
Struct(
foo: 0,
bar: 'hello world',
).toJson());
final struct = json.decodeStruct(
'{"foo": 0, "bar": "hello world"}',
);
}