json_mapper 0.2.0

  • README.md
  • Installing
  • Versions
  • 4

json_mapper

A Simple lightweight JSON mapping utility.

How do I use it?

Download the dependency through Dart Pub Package manager. Add the following line to your pubspec.yaml dependencies:

json_mapper: "any"

Once you're done, get the package using pub get, then import it:

import 'package:json_mapper/json_mapper.dart' as jmap;

To serialize an object:

Use the serialize(Object obj) function. It takes any Dart object.

import 'package:json_mapper/json_mapper.dart' as jmap;

class Contact {
  int name;
  int mobile;
  int email;
}

void main() {
  Contact bob = new Contact()
    ..name = 'Bob Smith'
    ..mobile = '4161234567'
    ..email = 'bob.smith@example.com'
    
  String json = jmap.serialize(bob);
  print(json);
}

The output should be similar to:

Use the deserialize(String json, Type type) function. It takes a string, and any Dart Type, even your own.

{"name":"Bob Smith","mobile":"4161234567","email":"bob.smith@example.com"}

To deserialize a string back to an object

...

void main() {
  String json = '{"name":"Bob Smith","mobile":"4161234567","email":"bob.smith@example.com"}';
  Contact bobFromJson = jmap.deserialize(json, Contact);
}

Use this package as a library

1. Depend on it

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


dependencies:
  json_mapper: ^0.2.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support 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_mapper/json_mapper.dart';
  
Version Uploaded Documentation Archive
0.2.0 Nov 26, 2014 Go to the documentation of json_mapper 0.2.0 Download json_mapper 0.2.0 archive
0.1.0 Nov 15, 2014 Go to the documentation of json_mapper 0.1.0 Download json_mapper 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
7
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0
Overall:
Weighted score of the above. [more]
4
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Issues and suggestions

Fix platform conflicts.

Error(s) prevent platform classification:

Fix dependencies in pubspec.yaml.

Fix dependencies in pubspec.yaml.

Running pub upgrade failed with the following output:

ERR: The current Dart SDK version is 2.0.0.
 
 Because json_mapper depends on unittest >=0.2.8+2 which requires SDK version <2.0.0, version solving failed.

Package is too old.

The package was released more than two years ago.

Maintain CHANGELOG.md.

Changelog entries help clients to follow the progress in your code.

Add SDK constraint in pubspec.yaml.

For information about setting SDK constraint, please see https://www.dartlang.org/tools/pub/pubspec#sdk-constraints.

The description is too short.

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Maintain an example.

Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use json_mapper.dart.

Format lib/json_mapper.dart.

Run dartfmt to format lib/json_mapper.dart.

Format lib/metadata.dart.

Run dartfmt to format lib/metadata.dart.

Format lib/test.dart.

Run dartfmt to format lib/test.dart.