jaguar_serializer 2.2.4

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 95

Pub Build Status Build Status Gitter

jaguar_serializer

Format agnostic Serializer library that can be used in vm, browser and flutter for JSON, mongodb, postgresql, etc

Getting Started

Install

#pubspec.yaml
dependencies:
  jaguar_serializer: 

dev_dependencies:
  build_runner: 
  jaguar_serializer_cli: 

Simple serializer

Import jaguar_serializer

import 'package:jaguar_serializer/jaguar_serializer.dart';

Create your model.

/// User model
class User {
  String name;
  int age;
}

Declare a Serializer for your model.

@GenSerializer()
class UserJsonSerializer extends Serializer<User> with _$UserJsonSerializer {
}

Include the generated serializer functionality.

part 'user.jser.dart';

Generate Serializer

Build

Now you can build you serializer running the command

pub run build_runner build

# flutter
flutter packages pub run build_runner build

This command will generate _$UserJsonSerializer in file 'user.jser.dart'.

Use Serializer

A Serializer will serialize and deserialize between your model and Map<String, dynamic>, that can be used to apply conversion to JSON, YAML, XML, etc.

import 'package:jaguar_serializer/jaguar_serializer.dart';
import 'model/user.dart';

void main() {
  final userSerializer = new UserJsonSerializer();
  
  User user = userSerializer.fromMap({
        'name': 'John',
        'age': 25
      });
  
  print(userSerializer.toMap(user));
}

Serializer repository

You can also use a JSON repository or implement one.

import 'package:jaguar_serializer/jaguar_serializer.dart';
import 'model/user.dart';

void main() {
  final jsonRepository = new JsonRepo()..add(new UserSerializer());
  
  User user = jsonRepository.from<User>('{"name":"John","age": 25}');
  
  print(jsonRepository.serialize(user));
}

Changelog

2.2.4

  • Replaced DateTimeMillisecondsProcessor with MillisecondsProcessor
  • Fixed MillisecondsProcessor utc bug

2.2.0

  • Dart 2 stable
  • Remove DateProcessor, use DateTimeProcessor instead
  • Remove DateTimeProcessor.utc() constructor
  • Add DateTimeUtcProcessor()
  • Remove date_format dependency

2.1.14

  • Added pass annotation

2.1.9

  • Exposed passProcessor

2.1.6

  • Added PassProcessor

2.1.5

  • Fixed bug when source is Map<dynamic, dynamic>

2.0.2

  • Set are not serializable

1.0.0-dev8

  • Add SafeNumberProcessor

1.0.0-dev7

  • fix flutter --release build

1.0.0-dev6

  • null safe processors

1.0.0-dev5

  • remove yaml support
    • easy to reimplement using yamlicious (example/basic/basic_main.dart)
  • add builtins processor (Date, numToString, stringToNum)

1.0.0-dev4

  • introduce field format to automatically convert field Example:

    class Model {  
      String myField;
    }
    @GenSerializer(fieldFormat: FieldFormat.snakeCase)
    class ModelSerializer extends Serializer ... {}
    
    final map = { 'my_field': 'foo' };
    final model = serializer.fromMap(map);
    print(model.myField); // print 'foo'
    
  • we now support final field deserialization

  • createModel() in Serializer class is now deprecated, it will be remove in the final release of 1.0.0

1.0.0-dev2

  • simplify and optimize generated code
  • fix processor inside List/Map

*** Breaking Changes ***

  • All Serializers are now nullable by default
  • Drop Map key processor
  • Only Map<String, dynamic> can be encode
  • toMap(null) return null
  • fromMap(null) return null
  • fromMap({}) return object

1.0.0-dev1

  • update to dart 2
  • support build.yaml and build_runner

0.5.1

  • Removed deprecated processors field in GenSerializer use processor field in Property instead

0.5.0

  • support disable null check
  • deprecate GenSerializer.processor fields, FieldProcessor go into GenSerializer.fields inside Property
  • support for default value, String, int, double, bool, if a field is non nullable, jaguar will use the default value declared in you object constructor

Breaking Change EnDecode, DecodeOnly, EncodeOnly does not use optional parameter in constructor anymore,

example: EnDecode({this.alias, bool isNullable, FieldProcessor<T, dynamic> processor, T defaultsTo})

0.4.2

  • Better support of ddc

0.4.1

  • Added docs
  • Fixed README

0.4.0

Breaking Changes

  • Generator is now in a separate package
  • Angular style annotations, only one annotation
@GenSerializer(
  fields: const {
    'field': const EncodeOnly('f')
  }, 
  ignore: const [
    'ignoreField'
  ], 
  processors: const {
   'dates': const DateTimeProcessor(),
  }, 
  serializers: const [
   FieldSerializer,
])

0.3.16

  • to, from, serialize, deserialize methods now handle null values correctly

0.3.15

  • serialize and deserialize methods now handle null values correctly

0.3.14

  • SerializerRepo handles when type is dynamic

0.3.12

  • Added from and to methods to SerializerRepo

0.3.11

  • SerializerRepo now serializes and de-serializes built-in types at the root like Map, List<List>, etc
  • added addAll method to SerializerRepo to add multiple serializers
  • Validation for RawData custom field processor

0.3.7

  • Add builtin RawData Processor
  • Optimize CustomFieldProcessor

0.3.6

  • Update build package to >=0.9.3 <0.10.0

0.3.5

  • serializers.yaml is now optional, Jaguar Serializer will take all dart files under lib, bin, example and test folders. Be careful on big project, watch can be slow or take a lot of resources.

0.3.4

  • Fixed ProvideSerializer for Map fields

0.3.3

  • Better failure messages when property is an Object or dynamic

0.3.2

  • Added "exclude by default" feature

0.3.1

  • Update build (>=0.7.0 <0.8.0)
  • serializer init command, generate serializer.yaml
  • fix overrided field in double inside the generated code

0.3.0

New

  • Repository system (Json, Yaml)
  • embeded type => see typeKey
  • Optional parameters for GenSerializer :
    • bool typeKey (default:true) if you want to include the type
    • String modelName value that will be include as a type.

0.1.2

First release.

Contains:

  1. Serializer for dart builtin types
  2. Custom serializers for fields
  3. Nested Map and List serializers

0.1.3

  • Fixed renaming encode field bug

0.1.6

  • Null nested objects are not serialized properly

example/example.dart

import 'package:jaguar_serializer/jaguar_serializer.dart';

part 'example.jser.dart';

class Player {
  String name;
  String email;
  int score;
  List<Address> address;

  Player({this.name, this.email, this.score, this.address});

  String toString() => 'Player($name, $email, $score, $address)';
}

class Address {
  String street;
  String city;

  Address({this.street, this.city});

  String toString() => 'Address($street, $city)';
}

@GenSerializer(serializers: const [AddressSerializer])
class PlayerSerializer extends Serializer<Player> with _$PlayerSerializer {}

@GenSerializer()
class AddressSerializer extends Serializer<Address> with _$AddressSerializer {}

void main() {
  // user basic serializer
  PlayerSerializer plSer = new PlayerSerializer();
  Player player = new Player(
      name: 'John',
      email: 'john@noemail.com',
      score: 1000,
      address: [(new Address(street: 'Skögsangavägen', city: 'Stockholm'))]);

  final Map map = plSer.toMap(player);
  print(map);

  Player decoded = plSer.fromMap(map);
  print(decoded);
}

Use this package as a library

1. Depend on it

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


dependencies:
  jaguar_serializer: ^2.2.4

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:jaguar_serializer/jaguar_serializer.dart';
  
Version Uploaded Documentation Archive
2.2.4 Sep 19, 2018 Go to the documentation of jaguar_serializer 2.2.4 Download jaguar_serializer 2.2.4 archive
2.2.2 Sep 10, 2018 Go to the documentation of jaguar_serializer 2.2.2 Download jaguar_serializer 2.2.2 archive
2.2.0 Aug 7, 2018 Go to the documentation of jaguar_serializer 2.2.0 Download jaguar_serializer 2.2.0 archive
2.1.14 Jul 5, 2018 Go to the documentation of jaguar_serializer 2.1.14 Download jaguar_serializer 2.1.14 archive
2.1.12 Jul 5, 2018 Go to the documentation of jaguar_serializer 2.1.12 Download jaguar_serializer 2.1.12 archive
2.1.10 Jun 29, 2018 Go to the documentation of jaguar_serializer 2.1.10 Download jaguar_serializer 2.1.10 archive
2.1.9 Jun 29, 2018 Go to the documentation of jaguar_serializer 2.1.9 Download jaguar_serializer 2.1.9 archive
2.1.8 Jun 26, 2018 Go to the documentation of jaguar_serializer 2.1.8 Download jaguar_serializer 2.1.8 archive
2.1.6 Jun 25, 2018 Go to the documentation of jaguar_serializer 2.1.6 Download jaguar_serializer 2.1.6 archive
2.1.5 Jun 19, 2018 Go to the documentation of jaguar_serializer 2.1.5 Download jaguar_serializer 2.1.5 archive

All 57 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
90
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]
95
Learn more about scoring.

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

  • Dart: 2.0.0
  • pana: 0.12.4

Platforms

Detected platforms: Flutter, web, other

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

Health suggestions

Fix lib/src/serializer/field_processor.dart. (-0.50 points)

Analysis of lib/src/serializer/field_processor.dart reported 1 hint:

line 247 col 45: 'DateTimeMillisecondsProcessor' is deprecated and shouldn't be used.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
Dev dependencies
build_runner ^0.10.0
jaguar_serializer_cli