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 * Setup | 10 * Setup |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 * or as an additional parameter to the reading methods. | 141 * or as an additional parameter to the reading methods. |
142 * | 142 * |
143 * new Serialization() | 143 * new Serialization() |
144 * ..addRuleFor(new Person(), constructorFields: ["name"]) | 144 * ..addRuleFor(new Person(), constructorFields: ["name"]) |
145 * ..externalObjects['Person'] = reflect(new Person()).type; | 145 * ..externalObjects['Person'] = reflect(new Person()).type; |
146 */ | 146 */ |
147 library serialization; | 147 library serialization; |
148 | 148 |
149 import 'src/mirrors_helpers.dart'; | 149 import 'src/mirrors_helpers.dart'; |
150 import 'src/serialization_helpers.dart'; | 150 import 'src/serialization_helpers.dart'; |
151 import 'src/polyfill_identity_set.dart'; | |
152 import 'dart:json' show JSON; | 151 import 'dart:json' show JSON; |
153 | 152 |
154 part 'src/reader_writer.dart'; | 153 part 'src/reader_writer.dart'; |
155 part 'src/serialization_rule.dart'; | 154 part 'src/serialization_rule.dart'; |
156 part 'src/basic_rule.dart'; | 155 part 'src/basic_rule.dart'; |
157 | 156 |
158 /** | 157 /** |
159 * This class defines a particular serialization scheme, in terms of | 158 * This class defines a particular serialization scheme, in terms of |
160 * [SerializationRule] instances, and supports reading and writing them. | 159 * [SerializationRule] instances, and supports reading and writing them. |
161 * See library comment for examples of usage. | 160 * See library comment for examples of usage. |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 // Make some bogus rule instances so we have something to feed rule creation | 392 // Make some bogus rule instances so we have something to feed rule creation |
394 // and get their types. If only we had class literals implemented... | 393 // and get their types. If only we had class literals implemented... |
395 var basicRule = new BasicRule(reflect(null).type, '', [], [], []); | 394 var basicRule = new BasicRule(reflect(null).type, '', [], [], []); |
396 | 395 |
397 var meta = new Serialization() | 396 var meta = new Serialization() |
398 ..selfDescribing = false | 397 ..selfDescribing = false |
399 ..addRuleFor(new ListRule()) | 398 ..addRuleFor(new ListRule()) |
400 ..addRuleFor(new PrimitiveRule()) | 399 ..addRuleFor(new PrimitiveRule()) |
401 ..addRuleFor(new ListRuleEssential()) | 400 ..addRuleFor(new ListRuleEssential()) |
402 ..addRuleFor(basicRule, | 401 ..addRuleFor(basicRule, |
403 constructorFields: ['typeWrapped', | 402 constructorFields: ['type', |
404 'constructorName', | 403 'constructorName', |
405 'constructorFields', 'regularFields', []], | 404 'constructorFields', 'regularFields', []], |
406 fields: []) | 405 fields: []) |
407 ..addRule(new NamedObjectRule()) | 406 ..addRule(new NamedObjectRule()) |
408 ..addRule(new MirrorRule()); | 407 ..addRule(new MirrorRule()); |
409 meta.namedObjects = namedObjects; | 408 meta.namedObjects = namedObjects; |
410 return meta; | 409 return meta; |
411 } | 410 } |
412 | 411 |
413 /** Return true if our [namedObjects] collection has an entry for [object].*/ | 412 /** Return true if our [namedObjects] collection has an entry for [object].*/ |
(...skipping 14 matching lines...) Expand all Loading... |
428 } | 427 } |
429 } | 428 } |
430 | 429 |
431 /** | 430 /** |
432 * An exception class for errors during serialization. | 431 * An exception class for errors during serialization. |
433 */ | 432 */ |
434 class SerializationException implements Exception { | 433 class SerializationException implements Exception { |
435 final String message; | 434 final String message; |
436 const SerializationException([this.message]); | 435 const SerializationException([this.message]); |
437 } | 436 } |
OLD | NEW |