Skip to content
Format (JSON, XML, protobuf, mongodb, etc) and platform (server, client) agnostic serialization framework
Branch: master
Clone or download
Latest commit 42acf0b Mar 26, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
mongo Upgraded to jaguar_serializer 2.2.x Dec 27, 2018
protobuf
serializer Double and Int to num field processors Mar 6, 2019
serializer_cli Minor changes Mar 26, 2019
tool remove fatal infos Aug 7, 2018
.gitignore Map<String, dynamic> support Sep 18, 2018
.travis.yml WIP: Travis: Build Jun 9, 2018
README.md dart 2 stable and fix test Aug 7, 2018
mono_repo.yaml init mono_repo Mar 31, 2018

README.md

Pub 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));
}
You can’t perform that action at this time.