jaguar_serializer

Last updated:

0 purchases

jaguar_serializer Image
jaguar_serializer Images
Add to Cart

Description:

jaguar serializer

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

Documentations

Getting Started #
Install #
#pubspec.yaml
dependencies:
jaguar_serializer:

dev_dependencies:
build_runner:
jaguar_serializer_cli:
copied to clipboard
Simple serializer #
Import jaguar_serializer
import 'package:jaguar_serializer/jaguar_serializer.dart';
copied to clipboard
Create your model.
/// User model
class User {
String name;
int age;
}
copied to clipboard
Declare a Serializer for your model.
@GenSerializer()
class UserJsonSerializer extends Serializer<User> with _$UserJsonSerializer {
}
copied to clipboard
Include the generated serializer functionality.
part 'user.jser.dart';
copied to clipboard
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
copied to clipboard
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));
}
copied to clipboard
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));
}
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.