Coder Social home page Coder Social logo

ixsv-com / dart_jaguar_serializer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jaguar-dart/jaguar_serializer

0.0 0.0 0.0 617 KB

Format (JSON, XML, protobuf, mongodb, etc) and platform (server, client) agnostic serialization framework

Shell 1.64% Dart 98.07% HTML 0.29%

dart_jaguar_serializer's Introduction

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

dart_jaguar_serializer's People

Contributors

tejainece avatar lejard-h avatar kleak avatar jaumard avatar escamoteur avatar maxkoshevoi avatar gedw99 avatar jalakoo avatar droplet-js avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.