json_object_mapper 1.0.0

  • Readme
  • Changelog
  • Installing
  • 73

json_object_mapper #

A simple and easy way to map Objects to/from Map and JSON with Web support.

Main features:

  • Compatible with Web (dart2js) and VM.

  • No code generation.

  • Uses Mirrors only if available in 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.fields(this.username, this.email);

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

  @override
  List<String> getObjectFields() {
    return getObjectFieldsDefault() ;
    //return ['username' , 'email'] ;
  }

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

}

main() {
  
      User user1 = User.fields("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.json( '{"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.

1.0.0 #

  • Initial version, created by Stagehand

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  json_object_mapper: ^1.0.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:json_object_mapper/json_object_mapper.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
49
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
73
Learn more about scoring.

We analyzed this package on May 29, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.2
  • pana: 0.13.8-dev

Health suggestions

Format lib/json_object_mapper.dart.

Run dartfmt to format lib/json_object_mapper.dart.

Format lib/src/json_object.dart.

Run dartfmt to format lib/src/json_object.dart.

Format lib/src/json_object_base.dart.

Run dartfmt to format lib/src/json_object_base.dart.

Fix additional 3 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/json_object_generic.dart (Run dartfmt to format lib/src/json_object_generic.dart.)
  • lib/src/json_object_html.dart (Run dartfmt to format lib/src/json_object_html.dart.)
  • lib/src/json_object_mirror.dart (Run dartfmt to format lib/src/json_object_mirror.dart.)

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and json_object_mapper.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
Dev dependencies
pedantic ^1.8.0
test ^1.6.0