serde_generator 1.1.2 copy "serde_generator: ^1.1.2" to clipboard
serde_generator: ^1.1.2 copied to clipboard

The generator for the dart_serde package, is responsible for generate the code that will serialize or deserialize an class

example/example.dart

// Remember, all this, will only work if you are using the complete dart_serde package,this package only contains the annotations

import 'dart:convert';

import 'package:serde/src/serde.dart';

@Serde()
class ExampleClass {
  bool attr1;
}

// Just from the annotations the code that will be generated is something like

ExampleClass _fromJson(Map<String, dynamic> data) {
  ExampleClass exampleClass = ExampleClass();
  exampleClass.attr1 = data['attr1'] as bool;
  return exampleClass;
}

String _toJson(ExampleClass instance) {
  Map<String, dynamic> mapper = {
    'attr1': instance.attr1.toString()
  };
  return json.encode(mapper);
}

// Then you have to add to your class
// factory ExampleClass.fromJson(Map<String, dynamic> data) => _fromJson(data);
//  and for serialize toJson(ExampleClass instance) => _toJson(instance);

// You can also add @Prop annotation to an field, if you want to change-it
0
likes
30
pub points
0%
popularity

Publisher

unverified uploader

The generator for the dart_serde package, is responsible for generate the code that will serialize or deserialize an class

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

analyzer, build, serde, source_gen

More

Packages that depend on serde_generator