json_object_mapper 1.0.1 copy "json_object_mapper: ^1.0.1" to clipboard
json_object_mapper: ^1.0.1 copied to clipboard

outdated

A simple and easy way to map Objects from JSON and to Map with support for Dart Native and Dart Web.

json_object_mapper #

pub package CI GitHub Tag New Commits Last Commits Pull Requests Code size License Funding Funding

A simple and easy way to map Objects from JSON and to Map with support for Dart Native and Dart Web.

Main features:

  • Works with simple Objects: no method implementation needed.

  • Compatible with Web (JS) and Native (VM) platforms.

  • No @annotations or code generation.

  • Only uses Mirrors if it's available in the platform (transparent load).

Usage #

A simple usage example:

import 'package:json_object_mapper/json_object_mapper.dart';

class User extends JSONObject {
  String username ;
  String email ;

  User.fromFields(this.username, this.email);

  User.fromJson(String json) {
    initializeFromJSON(json) ;
  }

  @override
  String toString() {
    return 'User{username: $username, email: $email}' ;
  }

}

main() {
  
      User user1 = User.fromFields("joe", "joe@mail.com") ;
      
      print("User[1]: $user1");      
      // User[1]: User{username: joe, email: joe@mail.com}

      print(user1.toJSON());
      // {"username":"joe","email":"joe@mail.com"}

      User user2 = User.fromJson( '{"username":"joe2","email":"joe2@mail.com"}' ) ;
      
      print("User[2]: $user2");
      // User[2]: User{username: joe2, email: joe2@mail.com}
      
      print(user2.toJson());
      // {"username":"joe2","email":"joe2@mail.com"}

}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Author #

Graciliano M. Passos: gmpassos@GitHub.

License #

Dart free & open-source license.

6
likes
0
pub points
36%
popularity

Publisher

unverified uploader

A simple and easy way to map Objects from JSON and to Map with support for Dart Native and Dart Web.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

More

Packages that depend on json_object_mapper