serde 1.0.5 copy "serde: ^1.0.5" to clipboard
serde: ^1.0.5 copied to clipboard

outdated

This packages contain the annotations for the package dart_serde.

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
1
likes
40
pub points
0%
popularity

Publisher

unverified uploader

This packages contain the annotations for the package dart_serde.

Repository (GitHub)
View/report issues

License

BSD-2-Clause (license)

Dependencies

build, source_gen

More

Packages that depend on serde