| 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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 // and get their types. If only we had class literals implemented... | 375 // and get their types. If only we had class literals implemented... |
| 377 var closureRule = new ClosureToMapRule.stub([].runtimeType); | 376 var closureRule = new ClosureToMapRule.stub([].runtimeType); |
| 378 var basicRule = new BasicRule(reflect(null).type, '', [], [], []); | 377 var basicRule = new BasicRule(reflect(null).type, '', [], [], []); |
| 379 | 378 |
| 380 var meta = new Serialization() | 379 var meta = new Serialization() |
| 381 ..selfDescribing = false | 380 ..selfDescribing = false |
| 382 ..addRuleFor(new ListRule()) | 381 ..addRuleFor(new ListRule()) |
| 383 ..addRuleFor(new PrimitiveRule()) | 382 ..addRuleFor(new PrimitiveRule()) |
| 384 ..addRuleFor(new ListRuleEssential()) | 383 ..addRuleFor(new ListRuleEssential()) |
| 385 ..addRuleFor(basicRule, | 384 ..addRuleFor(basicRule, |
| 386 constructorFields: ['typeWrapped', | 385 constructorFields: ['type', |
| 387 'constructorName', | 386 'constructorName', |
| 388 'constructorFields', 'regularFields', []], | 387 'constructorFields', 'regularFields', []], |
| 389 fields: []) | 388 fields: []) |
| 390 ..addRule(new ClassMirrorRule()); | 389 ..addRule(new ClassMirrorRule()); |
| 391 meta.externalObjects = externalObjects; | 390 meta.externalObjects = externalObjects; |
| 392 return meta; | 391 return meta; |
| 393 } | 392 } |
| 394 } | 393 } |
| 395 | 394 |
| 396 /** | 395 /** |
| 397 * An exception class for errors during serialization. | 396 * An exception class for errors during serialization. |
| 398 */ | 397 */ |
| 399 class SerializationException implements Exception { | 398 class SerializationException implements Exception { |
| 400 final String message; | 399 final String message; |
| 401 const SerializationException([this.message]); | 400 const SerializationException([this.message]); |
| 402 } | 401 } |
| OLD | NEW |