|
46 | 46 |
|
47 | 47 | <div class="Collapsible__content"> |
48 | 48 | <!-- Navigation --> |
49 | | - <ul class='Nav'><li class='Nav__item '><a href="../Getting_Started.html">Getting Started</a></li><li class='Nav__item '><a href="../Overview.html">Overview</a></li><li class='Nav__item has-children'><a href="../General_concepts/Overview.html" class="folder"><i class="Nav__arrow"> </i>General concepts</a><ul class='Nav'><li class='Nav__item '><a href="../General_concepts/Overview.html">Overview</a></li><li class='Nav__item '><a href="../General_concepts/Aggregation_tree.html">Aggregation tree</a></li><li class='Nav__item '><a href="../General_concepts/Updates_and_change_events.html">Updates and change events</a></li><li class='Nav__item '><a href="../General_concepts/Serialization.html">Serialization</a></li><li class='Nav__item '><a href="../General_concepts/Validation.html">Validation</a></li></ul></li><li class='Nav__item Nav__item--open has-children'><a href="../Record/Overview.html" class="folder"><i class="Nav__arrow"> </i>Record</a><ul class='Nav'><li class='Nav__item '><a href="../Record/Overview.html">Overview</a></li><li class='Nav__item '><a href="../Record/Aggregation_tree.html">Aggregation tree</a></li><li class='Nav__item '><a href="../Record/Updates_and_change_events.html">Updates and change events</a></li><li class='Nav__item '><a href="../Record/Validation.html">Validation</a></li><li class='Nav__item Nav__item--active'><a href="../Record/Serialization.html">Serialization</a></li><li class='Nav__item '><a href="../Record/id_ and_id-references.html">id and id-references</a></li></ul></li><li class='Nav__item has-children'><a href="../Collection/Overview.html" class="folder"><i class="Nav__arrow"> </i>Collection</a><ul class='Nav'><li class='Nav__item '><a href="../Collection/Overview.html">Overview</a></li><li class='Nav__item '><a href="../Collection/Proxied_array_methods.html">Proxied array methods</a></li><li class='Nav__item '><a href="../Collection/Iteration_methods.html">Iteration methods</a></li><li class='Nav__item '><a href="../Collection/Sorted_collections.html">Sorted collections</a></li><li class='Nav__item '><a href="../Collection/Serialization.html">Serialization</a></li><li class='Nav__item '><a href="../Collection/Updates_and_Events.html">Updates and Events</a></li><li class='Nav__item '><a href="../Collection/Validation.html">Validation</a></li></ul></li><li class='Nav__item '><a href="../Events.html">Events</a></li><li class='Nav__item '><a href="../Mixins.html">Mixins</a></li></ul> |
| 49 | + <ul class='Nav'><li class='Nav__item '><a href="../Getting_Started.html">Getting Started</a></li><li class='Nav__item has-children'><a href="../Record/Definition.html" class="folder"><i class="Nav__arrow"> </i>Record</a><ul class='Nav'><li class='Nav__item '><a href="../Record/Definition.html">Definition</a></li><li class='Nav__item '><a href="../Record/Updates_and_transactions.html">Updates and transactions</a></li><li class='Nav__item '><a href="../Record/Listening_to_events.html">Listening to events</a></li></ul></li><li class='Nav__item has-children'><a href="../Collection/Definition.html" class="folder"><i class="Nav__arrow"> </i>Collection</a><ul class='Nav'><li class='Nav__item '><a href="../Collection/Definition.html">Definition</a></li><li class='Nav__item '><a href="../Collection/Updates_and_transactions.html">Updates and transactions</a></li><li class='Nav__item '><a href="../Collection/Listening_to_events.html">Listening to events</a></li><li class='Nav__item '><a href="../Collection/Iteration_methods.html">Iteration methods</a></li><li class='Nav__item '><a href="../Collection/Sorted_collections.html">Sorted collections</a></li><li class='Nav__item '><a href="../Collection/Proxied_array_methods.html">Proxied array methods</a></li></ul></li><li class='Nav__item Nav__item--open has-children'><a href="../API_by_feature/Aggregation_tree.html" class="folder"><i class="Nav__arrow"> </i>API by feature</a><ul class='Nav'><li class='Nav__item '><a href="../API_by_feature/Aggregation_tree.html">Aggregation tree</a></li><li class='Nav__item Nav__item--active'><a href="../API_by_feature/Serialization.html">Serialization</a></li><li class='Nav__item '><a href="../API_by_feature/Validation.html">Validation</a></li><li class='Nav__item '><a href="../API_by_feature/Shared_objects.html">Shared objects</a></li><li class='Nav__item '><a href="../API_by_feature/id-references.html">id-references</a></li><li class='Nav__item '><a href="../API_by_feature/Stores.html">Stores</a></li></ul></li><li class='Nav__item '><a href="../Events.html">Events</a></li><li class='Nav__item '><a href="../Mixins.html">Mixins</a></li></ul> |
50 | 50 |
|
51 | 51 | <div class="Links"> |
52 | 52 | <hr/> |
|
77 | 77 | <div class="Page__header"> |
78 | 78 | <h1>Serialization</h1> |
79 | 79 | <span style="float: right; font-size: 10px; color: gray;"> |
80 | | - <a href="https://github.com/Volicon/React-MVx/blob/develop/docs/04_Record/05_Serialization.md" target="_blank">Edit on GitHub</a> |
| 80 | + <a href="https://github.com/Volicon/React-MVx/blob/develop/docs/06_API_by_feature/02_Serialization.md" target="_blank">Edit on GitHub</a> |
81 | 81 | </span> |
82 | 82 | </div> |
83 | 83 |
|
84 | 84 |
|
85 | 85 | <div class="s-content"> |
86 | | - <h1 id="page_Declarations">Declarations</h1> |
| 86 | + <p>Aggregation tree formed of records and collections is serializable by default. Record corresponds to an object in JSON, while the collection is represented as an array.</p> |
| 87 | +<h2 id="page_Serialization+API">Serialization API</h2> |
| 88 | +<h3 id="page_recordOrCollection.toJSON%28%29">recordOrCollection.toJSON()</h3> |
| 89 | +<p>Produces the JSON for the aggregation tree of the record or collection. May be overriden in particular record or collection.</p> |
| 90 | +<h3 id="page_new+RecordOrCollection%28+json%2C+%7B+parse+%3A+true+%7D+%29">new RecordOrCollection( json, { parse : true } )</h3> |
| 91 | +<p>Constructs an aggregation tree from its JSON representation.</p> |
| 92 | +<h3 id="page_recordOrCollection.set%28+json%2C+%7B+parse+%3A+true+%7D+%29">recordOrCollection.set( json, { parse : true } )</h3> |
| 93 | +<p>Update an aggregation tree from its JSON representation.</p> |
| 94 | +<h3 id="page_recordOrCollection.parse%28+json+%29">recordOrCollection.parse( json )</h3> |
| 95 | +<p>May be overriden to add custom JSON transformation.</p> |
| 96 | +<h2 id="page_Attribute-level+serialization+control">Attribute-level serialization control</h2> |
| 97 | +<p>Serialization can be controlled for the specific attribute in the Recrod's attribute definition.</p> |
87 | 98 | <h3 id="page_attr+%3A+Type.has.toJSON%28+false+%29"><code>attrDef</code> attr : Type.has.toJSON( false )</h3> |
88 | | -<p>Exclude attribute from serialization.</p> |
| 99 | +<p>Exclude attribute from the resulting JSON.</p> |
89 | 100 | <h3 id="page_attr+%3A+Type.has.toJSON%28+%28+value%2C+name+%29+%3D%3E+json+%29"><code>attrDef</code> attr : Type.has.toJSON( ( value, name ) => json )</h3> |
90 | 101 | <p>Override the default toJSON() method for the selected record's attribute.</p> |
91 | | -<h3 id="page_attr+%3A+Type.has.parse%28%29"><code>attrDef</code> attr : Type.has.parse()</h3> |
92 | | -<p>Transform the data before it will be passed to the record's attribute when <code>{ parse : true }</code> option is used.</p> |
93 | | -<h1 id="page_Class+members">Class members</h1> |
94 | | -<h3 id="page_record.parse%28+json+%29">record.parse( json )</h3> |
95 | | -<p>May be overriden to transform constructor or <code>set</code> argument when <code>{ parse : true }</code> option is used.</p> |
96 | | -<h3 id="page_constructor%28+json%2C+%7B+parse+%3A+true+%7D+%29">constructor( json, { parse : true } )</h3> |
97 | | -<p>Call <code>record.parse( json )</code> and attribute-level parse transforms. They won't be executed by default.</p> |
98 | | -<h3 id="page_record.set%28+json%2C+%7B+parse+%3A+true+%7D+%29">record.set( json, { parse : true } )</h3> |
99 | | -<p>Call <code>record.parse( json )</code> and attribute-level parse transforms. They won't be executed by default.</p> |
100 | | -<h3 id="page_record.toJSON%28%29">record.toJSON()</h3> |
101 | | -<p>Create record's JSON representation. This can be used for persistence, serialization, or for augmentation before being sent to the server. |
102 | | -The name of this method is a bit confusing, as it doesn't actually return a JSON string — but I'm afraid that it's the way that the JavaScript API for JSON.stringify works.</p> |
103 | | -<pre><code class="language-javascript">@define class Artist extends Record { |
104 | | - static attributes = { |
105 | | - firstName: String, |
106 | | - lastName: String, |
107 | | - birthday : Date, |
108 | | - code : String.has.toJSON( x => x.toLowerCase() ) |
109 | | - } |
110 | | -} |
111 | | - |
112 | | -const artist = new Artist({ |
113 | | - firstName: "Wassily", |
114 | | - lastName: "Kandinsky" |
115 | | -}); |
116 | | - |
117 | | -artist.birthday = new Date( 1866, 12, 16 ); |
118 | | - |
119 | | -alert( JSON.stringify( artist ) ); |
120 | | -</code></pre> |
121 | | -<p>It will, however, produce correct JSON for all the complex attribute types.</p> |
| 102 | +<h3 id="page_attr+%3A+Type.has.parse%28+%28+json%2C+name+%29+%3D%3E+value+%29"><code>attrDef</code> attr : Type.has.parse( ( json, name ) => value )</h3> |
| 103 | +<p>Transform the data before it will be passed to the record's attribute.</p> |
122 | 104 | </div> |
123 | 105 |
|
124 | 106 | <nav> |
125 | 107 | <ul class="Pager"> |
126 | | - <li class=Pager--prev><a href="../Record/Validation.html">Previous</a></li> <li class=Pager--next><a href="../Record/id_ and_id-references.html">Next</a></li> </ul> |
| 108 | + <li class=Pager--prev><a href="../API_by_feature/Aggregation_tree.html">Previous</a></li> <li class=Pager--next><a href="../API_by_feature/Validation.html">Next</a></li> </ul> |
127 | 109 | </nav> |
128 | 110 | </article> |
129 | 111 |
|
|
0 commit comments