OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * This provides a general-purpose serialization facility for Dart objects. A | 6 * This provides a general-purpose serialization facility for Dart objects. A |
7 * [Serialization] is defined in terms of [SerializationRule]s and supports | 7 * [Serialization] is defined in terms of [SerializationRule]s and supports |
8 * reading and writing to different formats. | 8 * reading and writing to different formats. |
9 * | 9 * |
| 10 * ## Installing ## |
| 11 * |
| 12 * Use [pub][] to install this package. Add the following to your `pubspec.yaml` |
| 13 * file. |
| 14 * |
| 15 * dependencies: |
| 16 * serialization: any |
| 17 * |
| 18 * Then run `pub install`. |
| 19 * |
| 20 * For more information, see the |
| 21 * [serialization package on pub.dartlang.org][pkg]. |
| 22 * |
10 * Setup | 23 * Setup |
11 * ===== | 24 * ===== |
12 * A simple example of usage is | 25 * A simple example of usage is |
13 * | 26 * |
14 * var address = new Address(); | 27 * var address = new Address(); |
15 * address.street = 'N 34th'; | 28 * address.street = 'N 34th'; |
16 * address.city = 'Seattle'; | 29 * address.city = 'Seattle'; |
17 * var serialization = new Serialization() | 30 * var serialization = new Serialization() |
18 * ..addRuleFor(address); | 31 * ..addRuleFor(address); |
19 * Map output = serialization.write(address); | 32 * Map output = serialization.write(address); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 * take a [ClassMirror] in their constructor, and we cannot serialize those. So | 187 * take a [ClassMirror] in their constructor, and we cannot serialize those. So |
175 * when we read the rules, we must provide a Map<String, Object> which maps from | 188 * when we read the rules, we must provide a Map<String, Object> which maps from |
176 * the simple name of classes we are interested in to a [ClassMirror]. This can | 189 * the simple name of classes we are interested in to a [ClassMirror]. This can |
177 * be provided either in the [namedObjects] variable of the Serialization, | 190 * be provided either in the [namedObjects] variable of the Serialization, |
178 * or as an additional parameter to the reading and writing methods on the | 191 * or as an additional parameter to the reading and writing methods on the |
179 * [Reader] or [Writer] respectively. | 192 * [Reader] or [Writer] respectively. |
180 * | 193 * |
181 * new Serialization() | 194 * new Serialization() |
182 * ..addRuleFor(new Person(), constructorFields: ["name"]) | 195 * ..addRuleFor(new Person(), constructorFields: ["name"]) |
183 * ..namedObjects['Person'] = reflect(new Person()).type; | 196 * ..namedObjects['Person'] = reflect(new Person()).type; |
| 197 * |
| 198 * [pub]: http://pub.dartlang.org |
| 199 * [pkg]: http://pub.dartlang.org/packages/serialization |
184 */ | 200 */ |
185 library serialization; | 201 library serialization; |
186 | 202 |
187 import 'src/mirrors_helpers.dart'; | 203 import 'src/mirrors_helpers.dart'; |
188 import 'src/serialization_helpers.dart'; | 204 import 'src/serialization_helpers.dart'; |
189 import 'dart:async'; | 205 import 'dart:async'; |
190 import 'dart:json' as json; | 206 import 'dart:json' as json; |
191 import 'dart:collection'; | 207 import 'dart:collection'; |
192 | 208 |
193 part 'src/reader_writer.dart'; | 209 part 'src/reader_writer.dart'; |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 } | 485 } |
470 | 486 |
471 /** | 487 /** |
472 * An exception class for errors during serialization. | 488 * An exception class for errors during serialization. |
473 */ | 489 */ |
474 class SerializationException implements Exception { | 490 class SerializationException implements Exception { |
475 final String message; | 491 final String message; |
476 const SerializationException([this.message]); | 492 const SerializationException([this.message]); |
477 toString() => "SerializationException($message)"; | 493 toString() => "SerializationException($message)"; |
478 } | 494 } |
OLD | NEW |