Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: pkg/serialization/lib/serialization.dart

Issue 13581006: Fix bug in code sample (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 * ===== 11 * =====
12 * A simple example of usage is 12 * A simple example of usage is
13 * 13 *
14 * var address = new Address(); 14 * var address = new Address();
15 * address.street = 'N 34th'; 15 * address.street = 'N 34th';
16 * address.city = 'Seattle'; 16 * address.city = 'Seattle';
17 * var serialization = new Serialization() 17 * var serialization = new Serialization()
18 * ..addRuleFor(address); 18 * ..addRuleFor(address);
19 * String output = serialization.write(address); 19 * Map output = serialization.write(address);
20 * 20 *
21 * This creates a new serialization and adds a rule for address objects. Right 21 * This creates a new serialization and adds a rule for address objects. Right
22 * now it has to be passed an address instance because of limitations using 22 * now it has to be passed an address instance because of limitations using
23 * Address as a literal. Then we ask the Serialization to write the address 23 * Address as a literal. Then we ask the [Serialization] to write the address
24 * and we get back a Map which is a [json]able representation of the state of 24 * and we get back a Map which is a [json]able representation of the state of
25 * the address and related objects. 25 * the address and related objects. Note that while the output in this case
26 * is a [Map], the type will vary depending on which output format we've told
27 * the [Serialization] to use.
26 * 28 *
27 * The version above used reflection to automatically identify the public 29 * The version above used reflection to automatically identify the public
28 * fields of the address object. We can also specify those fields explicitly. 30 * fields of the address object. We can also specify those fields explicitly.
29 * 31 *
30 * var serialization = new Serialization() 32 * var serialization = new Serialization()
31 * ..addRuleFor(address, 33 * ..addRuleFor(address,
32 * constructor: "create", 34 * constructor: "create",
33 * constructorFields: ["number", "street"], 35 * constructorFields: ["number", "street"],
34 * fields: ["city"]); 36 * fields: ["city"]);
35 * 37 *
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 } 469 }
468 470
469 /** 471 /**
470 * An exception class for errors during serialization. 472 * An exception class for errors during serialization.
471 */ 473 */
472 class SerializationException implements Exception { 474 class SerializationException implements Exception {
473 final String message; 475 final String message;
474 const SerializationException([this.message]); 476 const SerializationException([this.message]);
475 toString() => "SerializationException($message)"; 477 toString() => "SerializationException($message)";
476 } 478 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698