dartson 0.1.1

  • README.md
  • Installing
  • Versions
  • --

dartson

Build Status

Dartson is a Dart library that can be used to convert Dart objects into a JSON string. It uses dart:mirrors reflection to rebuild the schema. It also works in dart2js when using the dartson builder.

NOTICE: dart2js support is currently in development. It will be done soon.

Serializing objects in dart

library example;

import 'package:dartson/dartson.dart';

// If the builder should recognize this class add the following annotation
@DartsonEntity()
class EntityClass {
  String name;
  
  @DartsonProperty(name:"renamed")
  bool otherName;
  
  @DartsonProperty(ignore:true)
  String notVisible;
  
  // private members are never serialized
  String _private = "name";
  
  String get doGetter => _private;
}

void main() {
  EntityClass object = new EntityClass();
  object.name = "test";
  object.otherName = "blub";
  object.notVisible = "hallo";
  
  String jsonString = serialize(object);
  print(jsonString);
  // will return: '{"name":"test","renamed":"blub","doGetter":"name"}'
}

Parsing json to dart object

library example;

import 'package:dartson/dartson.dart';

// If the builder should recognize this class add the following annotation
@DartsonEntity()
class EntityClass {
  String name;
  String _setted;
  
  @DartsonProperty(name:"renamed")
  bool otherName;
  
  @DartsonProperty(ignore:true)
  String notVisible;
  
  List<EntityClass> children;
  
  set setted(String s) => _setted = s;
  String get setted => _setted;
}

void main() {
  EntityClass object = parse('{"name":"test","renamed":"blub","notVisible":"it is", "setted": "awesome"}', EntityClass);
  
  print(object.name); // > test
  print(object.otherName); // > blub
  print(object.notVisible); // > it is
  print(object.setted); // > awesome
  
  // to parse a list of items use [parseList]
  List<EntityClass> list = parseList('[{"name":"test", "children": [{"name":"child1"},{"name":"child2"}]},{"name":"test2"}]', EntityClass);
  print(list.length); // > 2
  print(list[0].name); // > test
  print(list[0].children[0].name); // > child1
}

TODO

  • Better dart2js solution
  • Handle recrusive errors

Use this package as a library

1. Depend on it

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


dependencies:
  dartson: ^0.1.1

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:dartson/dartson.dart';
  
Version Uploaded Documentation Archive
0.2.7 Mar 31, 2017 Go to the documentation of dartson 0.2.7 Download dartson 0.2.7 archive
0.2.6 Oct 5, 2016 Go to the documentation of dartson 0.2.6 Download dartson 0.2.6 archive
0.2.5 Oct 19, 2015 Go to the documentation of dartson 0.2.5 Download dartson 0.2.5 archive
0.2.4 Jul 4, 2015 Go to the documentation of dartson 0.2.4 Download dartson 0.2.4 archive
0.2.3 May 26, 2015 Go to the documentation of dartson 0.2.3 Download dartson 0.2.3 archive
0.2.2 Mar 2, 2015 Go to the documentation of dartson 0.2.2 Download dartson 0.2.2 archive
0.2.1 Feb 13, 2015 Go to the documentation of dartson 0.2.1 Download dartson 0.2.1 archive
0.2.0 Jan 29, 2015 Go to the documentation of dartson 0.2.0 Download dartson 0.2.0 archive
0.1.6 Jun 6, 2014 Go to the documentation of dartson 0.1.6 Download dartson 0.1.6 archive
0.1.5 Mar 15, 2014 Go to the documentation of dartson 0.1.5 Download dartson 0.1.5 archive

All 19 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
--
Health:
Code health derived from static analysis. [more]
--
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
--
Overall:
Weighted score of the above. [more]
--
Learn more about scoring.

This package version is not analyzed, because it is more than two years old. Check the latest stable version for its analysis.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=0.7.5