serde 1.0.6

  • Readme
  • Changelog
  • Example
  • Installing
  • 73

Dart Serde #

The aim of that package is provide an easy and friendly interface to use serialization and deserialization for classes;

Installation #

Add to dependencies #

Add those to your pubspec

dependencies:
  serde: ^1.0.0

dev_dependencies:
  build_runner: ^1.0.0
  serde_generator: ^1.0.0

Run pub get

Getting started #

Given the class

class Public {
    final bool mustShow;
    final int number;
}

To map a json into it, and from it you must do:

@Serde()
class Public {...}

And thats it.

If you have special conditions for some keys, that is treatable. Lets assume, for example, that the field musShow, comes int he json with the name show, and nested in the structure, wrapped by the mapper

@Serde()
class Public {
    @Prop(name: 'show', isNested: true, path: 'mapper')
    final bool mustShow;
    final int number;
}

1.0.0 - First release #

do the minimun necessary to make it work

1.0.1 #

  • Put into dartfmt

1.0.2 #

  • Add the options of serialize function and deserialize function

1.0.3 #

  • Example file and documentation

1.0.4 #

  • Turning this into the main repository, and deleting the dart_serde

1.0.5 #

  • Documenting the public API

1.0.6 #

  • Add option on @Serde of case
  • Change the default of nullable to true

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

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  serde: ^1.0.6

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:serde/serde.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
46
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
73
Learn more about scoring.

We analyzed this package on Oct 9, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:serde/serde.dart.

Health suggestions

Format lib/serde.dart.

Run dartfmt to format lib/serde.dart.

Format lib/src/prop.dart.

Run dartfmt to format lib/src/prop.dart.

Format lib/src/serde.dart.

Run dartfmt to format lib/src/serde.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
build >=0.12.0 <2.0.0 1.2.0
source_gen ^0.9.0 0.9.4+5
Transitive dependencies
analyzer 0.38.5
args 1.5.2
async 2.4.0
charcode 1.1.2
collection 1.14.12
convert 2.1.1
crypto 2.1.3
csslib 0.16.1
dart_style 1.3.1
front_end 0.1.27
glob 1.1.7
html 0.14.0+3
kernel 0.3.27
logging 0.11.3+2
meta 1.1.7
package_config 1.1.0
path 1.6.4
pedantic 1.8.0+1
pub_semver 1.4.2
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+12
yaml 2.2.0
Dev dependencies
test ^1.0.0