jaguar_serializer 2.1.6 copy "jaguar_serializer: ^2.1.6" to clipboard
jaguar_serializer: ^2.1.6 copied to clipboard

outdatedDart 1 only

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 #

#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));
}
7
likes
0
pub points
8%
popularity

Publisher

unverified uploader

Platform and format agnostic serializer built using source_gen

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

date_format

More

Packages that depend on jaguar_serializer