-
Notifications
You must be signed in to change notification settings - Fork 14
Parsing json to dart object
Luis Vargas edited this page Mar 13, 2015
·
1 revision
library example;
import 'package:dson/dson.dart';
@MirrorsUsed(targets:const['example'],override:'*')
import 'dart:mirrors';
class EntityClass {
String name;
String _setted;
@Property(name:"renamed")
bool otherName;
@ignore
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
}
- Serialization
1.1. Serializing objects
1.2. Serializing Cyclical Objects
1.3. Excluding attributes from being serialized
- Deserialization