Skip to content

Instantly share code, notes, and snippets.

@kasperpeulen
Last active August 29, 2015 14:25
Show Gist options
  • Select an option

  • Save kasperpeulen/ef38c9bda5dc586a78f1 to your computer and use it in GitHub Desktop.

Select an option

Save kasperpeulen/ef38c9bda5dc586a78f1 to your computer and use it in GitHub Desktop.
Dartson is a dart library which converts Dart Objects into their JSON representation.

#dartson:dartson example

Dartson is a dart library which converts Dart Objects into their JSON representation.

It helps you keep your code clean of fromJSON and toJSON functions by using dart:mirrors reflection. It works after dart2js compiling.

Main library: dartson:dartson
Main elements: Dartson.JSON Dartson.encode
Gist: https://gist.github.com/kasperpeulen/ef38c9bda5dc586a78f1

import 'dart:convert';
import 'package:dartson/dartson.dart';
@Entity()
class GeneralFacts {
String firstName = "Kasper";
String lastName = "Peulen";
String get fullName => '$firstName $lastName';
@Property(name : "best_language")
String bestLanguage = "Dart";
@Property(name : "best_chat")
String bestChat = "https://dartlang.slack.com";
int ten = 10;
bool truth = true;
String _private = 'will not be serialized';
}
void main() {
String jsonString = new Dartson.JSON().encode(new GeneralFacts());
print(prettify(jsonString));
}
String prettify(String json) =>
new JsonEncoder.withIndent(' ').convert(JSON.decode(json));
name: dartson.dartson_Dartson.JSON_Dartson.encode
description: |
Dartson is a dart library which converts Dart Objects into their JSON representation.
It helps you keep your code clean of fromJSON and toJSON functions by using `dart:mirrors` reflection. It works after dart2js compiling.
homepage: https://gist.github.com/kasperpeulen/ef38c9bda5dc586a78f1
environment:
sdk: '>=1.0.0 <2.0.0'
dependencies:
dartson: '>=0.2.4 <0.3.0'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment