dartson 0.1.4

  • README.md
  • changelog.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.

NOTICE: Latest tests using dart > 1.1.0 passed successful using dart2js without any further adjustments. Feedback is appreciated!

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
}

Roadmap

dart2js

I'm thinking of a transformer which saves the hole mirrors reflection and increases the performance. It also should reduce the JavaScript size.

Custom serializing handler

Version 0.2.0 will have the functionality to define the way you want to encode / decode specific types.

TODO

  • Better dart2js solution
  • Handle recrusive errors

Changelog

0.1.4

  • Fixed @MirrorsUsed annotations
  • added map and mapList functions to use an already parsed map

Use this package as a library

1. Depend on it

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


dependencies:
  dartson: ^0.1.4

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 15 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 >=1.0.0