jaguar_serializer 2.2.12
jaguar_serializer: ^2.2.12 copied to clipboard

Dart native js
Flutter Android iOS web

Platform and format agnostic serializer built using source_gen

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 #



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.

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

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}');