Subversion Repository Public Repository

ChrisCompleteCodeTrunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
<?xml version="1.0" encoding="utf-8"?>
<topic id="SerializationSettings" revisionNumber="1">
  <developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
    <!--
    <summary>
      <para>Optional summary abstract</para>
    </summary>
    -->
    <introduction>
      <para>JsonSerializer has a number of properties on it to customize how it serializes JSON. These can also be used
      with the methods on JsonConvert via the <codeEntityReference>T:Newtonsoft.Json.JsonSerializerSettings</codeEntityReference> overloads.</para>
    </introduction>
<sections>
<section>
 <title>DateFormatHandling</title>
 <content><para><codeEntityReference>T:Newtonsoft.Json.DateFormatHandling</codeEntityReference> controls how dates are serialized.</para>
 
<table>
  <tableHeader>
    <row>
      <entry><para>Member</para></entry>
      <entry><para>Description</para></entry>
    </row>
  </tableHeader>
  <row>
    <entry><para><legacyBold>IsoDateFormat</legacyBold></para></entry>
    <entry><para>By default Json.NET writes dates in the ISO 8601 format, e.g. <codeInline>"2012-03-21T05:40Z"</codeInline>.</para></entry>
  </row>
  <row>
    <entry><para><legacyBold>MicrosoftDateFormat</legacyBold></para></entry>
    <entry><para>Dates are written in the Microsoft JSON format, e.g. <codeInline>"\/Date(1198908717056)\/"</codeInline>.</para></entry>
  </row>
</table>

</content>
</section>

<section>
 <title>MissingMemberHandling</title>
 <content><para><codeEntityReference>T:Newtonsoft.Json.MissingMemberHandling</codeEntityReference> controls how missing members, e.g. JSON contains a property that isn't a member on the object, are handled during deserialization.</para>
 
<table>
  <tableHeader>
    <row>
      <entry><para>Member</para></entry>
      <entry><para>Description</para></entry>
    </row>
  </tableHeader>
  <row>
    <entry><para><legacyBold>Ignore</legacyBold></para></entry>
    <entry><para>By default Json.NET ignores JSON if there is no field or property for its value to be set to during deserialization.</para></entry>
  </row>
  <row>
    <entry><para><legacyBold>Error</legacyBold></para></entry>
    <entry><para>Json.NET errors when there is a missing member during deserialization.</para></entry>
  </row>
</table>

</content>
</section>

<section>
 <title>ReferenceLoopHandling</title>
 <content>
   <para><codeEntityReference>T:Newtonsoft.Json.ReferenceLoopHandling</codeEntityReference> controls how circular referencing objects,
   e.g. a Person object referencing itself via a Manager property, are serialized.</para>
   <para>The <codeEntityReference>M:System.Object.Equals(System.Object)</codeEntityReference> method is used to test whether an object is in a circular reference.
   By default <codeInline>Object.Equals(Object)</codeInline> will test whether the references are equal for reference types and private and public values
   are equal for value types. Classes and structs can override this method.</para> 
<table>
  <tableHeader>
    <row>
      <entry><para>Member</para></entry>
      <entry><para>Description</para></entry>
    </row>
  </tableHeader>
  <row>
    <entry><para>Error</para></entry>
    <entry><para>By default Json.NET will error if a reference loop is encountered (otherwise the serializer will get into an infinite loop).</para></entry>
  </row>
  <row>
    <entry><para>Ignore</para></entry>
    <entry><para>Json.NET will ignore objects in reference loops and not serialize them. The first time an object is encountered it will be serialized as usual but if the object is encountered as a child object of itself the serializer will skip serializing it.</para></entry>
  </row>
  <row>
    <entry><para>Serialize</para></entry>
    <entry><para>This option forces Json.NET to serialize objects in reference loops. This is useful if objects are nested but not indefinitely.</para></entry>
  </row>
</table>
<para>ReferenceLoopHandling can be used as an argument when calling the serializer, it can be set on an object's properties or
a collection's items using <codeEntityReference>P:Newtonsoft.Json.JsonContainerAttribute.ItemReferenceLoopHandling</codeEntityReference>,
customized on a property with <codeEntityReference>P:Newtonsoft.Json.JsonPropertyAttribute.ReferenceLoopHandling</codeEntityReference>
or a property's object properties or collection items using
<codeEntityReference>P:Newtonsoft.Json.JsonPropertyAttribute.ItemReferenceLoopHandling</codeEntityReference>.</para>
</content>
</section>

<section>
 <title>NullValueHandling</title>
 <content><para><codeEntityReference>T:Newtonsoft.Json.NullValueHandling</codeEntityReference> controls how null values on .NET objects are handled during serialization and how null values in JSON are handled during deserialization.</para>
 
<table>
  <tableHeader>
    <row>
      <entry><para>Member</para></entry>
      <entry><para>Description</para></entry>
    </row>
  </tableHeader>
  <row>
    <entry><para>Include</para></entry>
    <entry><para>By default Json.NET writes null values to JSON when serializing and sets null values to fields/properties when deserializing.</para></entry>
  </row>
  <row>
    <entry><para>Ignore</para></entry>
    <entry><para>Json.NET will skip writing JSON properties if the .NET value is null when serializing and will skip setting fields/properties if the JSON property is null when deserializing.</para></entry>
  </row>
</table>
<para>NullValueHandling can also be customized on individual properties with JsonPropertyAttribute.</para>

</content>
</section>

<section>
 <title>DefaultValueHandling</title>
 <content><para><codeEntityReference>T:Newtonsoft.Json.DefaultValueHandling</codeEntityReference> controls how Json.NET uses default values set using the .NET <codeEntityReference>T:System.ComponentModel.DefaultValueAttribute</codeEntityReference> when serializing and deserializing.</para>
 
<table>
  <tableHeader>
    <row>
      <entry><para>Member</para></entry>
      <entry><para>Description</para></entry>
    </row>
  </tableHeader>
  <row>
    <entry><para><legacyBold>Include</legacyBold></para></entry>
    <entry><para>By default Json.NET will write a field/property value to JSON when serializing if the value is the same as the field/property's default value.
    The Json.NET deserializer will continue setting a field/property if the JSON value is the same as the default value.</para></entry>
  </row>
  <row>
    <entry><para><legacyBold>Ignore</legacyBold></para></entry>
    <entry><para>Json.NET will skip writing a field/property value to JSON if the value is the same as the field/property's default value, or the custom
    value specified in <codeEntityReference>T:System.ComponentModel.DefaultValueAttribute</codeEntityReference> if the attribute is present. The Json.NET deserializer
    will skip setting a .NET object's field/property if the JSON value is the same as the default value.</para></entry>
  </row>
</table>
<para>DefaultValueHandling can also be customized on individual properties with JsonPropertyAttribute.</para>

</content>
</section>

<section>
 <title>ObjectCreationHandling</title>
 <content><para><codeEntityReference>T:Newtonsoft.Json.ObjectCreationHandling</codeEntityReference> controls how objects are created and deserialized to during deserialization.</para>
 
<table>
  <tableHeader>
    <row>
      <entry><para>Member</para></entry>
      <entry><para>Description</para></entry>
    </row>
  </tableHeader>
  <row>
    <entry><para><legacyBold>Auto</legacyBold></para></entry>
    <entry><para>By default Json.NET will attempt to set JSON values onto existing objects and add JSON values to existing collections during deserialization. </para></entry>
  </row>
  <row>
    <entry><para><legacyBold>Reuse</legacyBold></para></entry>
    <entry><para>Same behaviour as auto.</para></entry>
  </row>
  <row>
    <entry><para><legacyBold>Replace</legacyBold></para></entry>
    <entry><para>Json.NET will always recreate objects and collections before setting values to them during deserialization.</para></entry>
  </row>
</table>
<para>ObjectCreationHandling can also be customized on individual properties with JsonPropertyAttribute.</para>

</content>
</section>

<section>
 <title>TypeNameHandling</title>
 <content>
 <alert class="caution">
  <para>
 <codeEntityReference>T:Newtonsoft.Json.TypeNameHandling</codeEntityReference> should be used with caution when your application deserializes JSON from an external source.
  </para>
  <para>
    Incoming types should be validated with a custom <codeEntityReference>T:System.Runtime.Serialization.SerializationBinder</codeEntityReference> when deserializing with a value other than <c>TypeNameHandling.None</c>.
  </para>
 </alert>
 
 <para>
   <codeEntityReference>T:Newtonsoft.Json.TypeNameHandling</codeEntityReference> controls whether Json.NET includes .NET type names
   during serialization with a $type property and reads .NET type names from that property to determine what type to create during
   deserialization.
 </para>
 <para>
   The value of the $type property can be customized and validated by creating your own 
   <codeEntityReference>T:System.Runtime.Serialization.SerializationBinder</codeEntityReference>.
 </para>

<table>
  <tableHeader>
    <row>
      <entry><para>Member</para></entry>
      <entry><para>Description</para></entry>
    </row>
  </tableHeader>
  <row>
    <entry><para><legacyBold>None</legacyBold></para></entry>
    <entry><para>By default Json.NET does not read or write type names during deserialization.</para></entry>
  </row>
  <row>
    <entry><para><legacyBold>Objects</legacyBold></para></entry>
    <entry><para>Json.NET will write and use type names for objects but not collections.</para></entry>
  </row>
  <row>
    <entry><para><legacyBold>Arrays</legacyBold></para></entry>
    <entry><para>Json.NET will write and use type names for collections but not objects.</para></entry>
  </row>
  <row>
    <entry><para><legacyBold>Auto</legacyBold></para></entry>
    <entry><para>Json.NET will check whether an object/collection matches its declared property and writes the type name if they do not match, e.g. a property with a type of Mammal has a derived instance of Dog assigned. Auto will ensure that type information isn't lost when serializing/deserializing automatically without having to write type names for every object.</para></entry>
  </row>
  <row>
    <entry><para><legacyBold>All</legacyBold></para></entry>
    <entry><para>Json.NET will write and use type names for objects and collections.</para></entry>
  </row>
</table>
<para>TypeNameHandling can be used as an argument when calling the serializer, it can be set on an object's properties or
a collection's items using <codeEntityReference>P:Newtonsoft.Json.JsonContainerAttribute.ItemTypeNameHandling</codeEntityReference>,
customized on a property with <codeEntityReference>P:Newtonsoft.Json.JsonPropertyAttribute.TypeNameHandling</codeEntityReference>
or a property's object properties or collection items using
<codeEntityReference>P:Newtonsoft.Json.JsonPropertyAttribute.ItemTypeNameHandling</codeEntityReference>.</para>
</content>
</section>

<section>
 <title>TypeNameAssemblyFormat</title>
 <content><para><codeEntityReference>T:System.Runtime.Serialization.Formatters.FormatterAssemblyStyle</codeEntityReference> controls how type names are written during serialization.</para>
 
<table>
  <tableHeader>
    <row>
      <entry><para>Member</para></entry>
      <entry><para>Description</para></entry>
    </row>
  </tableHeader>
  <row>
    <entry><para><legacyBold>Simple</legacyBold></para></entry>
    <entry><para>By default Json.NET writes the partial assembly name with the type, e.g. System.Data.DataSet, System.Data. Note that Silverlight and Windows Phone are not able to use this format.</para></entry>
  </row>
  <row>
    <entry><para><legacyBold>Full</legacyBold></para></entry>
    <entry><para>Json.NET will write the full assembly name, including version number, culture and public key token.</para></entry>
  </row>
</table>
<para>Read more about the valid values at <codeEntityReference>T:System.Runtime.Serialization.Formatters.FormatterAssemblyStyle</codeEntityReference>.</para>

</content>
</section>

<section>
 <title>Binder</title>
 <content><para>The <codeEntityReference>T:System.Runtime.Serialization.SerializationBinder</codeEntityReference> is used to resolve type names to a .NET type.</para>
 <para>Read more about the serialization binder here: <codeEntityReference>T:System.Runtime.Serialization.SerializationBinder</codeEntityReference></para>
</content>
</section>

<section>
 <title>ConstructorHandling</title>
 <content><para><codeEntityReference>T:Newtonsoft.Json.ConstructorHandling</codeEntityReference> controls how constructors are used when initializing objects during deserialization.</para>
 
<table>
  <tableHeader>
    <row>
      <entry><para>Member</para></entry>
      <entry><para>Description</para></entry>
    </row>
  </tableHeader>
  <row>
    <entry><para><legacyBold>Default</legacyBold></para></entry>
    <entry><para>By default Json.NET will first look for a constructor marked with the JsonConstructorAttribute, then look for a public default constructor
    (a constructor that doesn't take any arguments), then check if the class has a single public constructor with arguments and finally check for a
    non-public default constructor. If the class has multiple public constructors with arguments an error will be thrown. This can be fixed by
    marking one of the constructors with the JsonConstructorAttribute.</para></entry>
  </row>
  <row>
    <entry><para><legacyBold>AllowNonPublicDefaultConstructor</legacyBold></para></entry>
    <entry><para>Json.NET will use a classes private default constructor before constructors with arguments if available. </para></entry>
  </row>
</table>

</content>
</section>

<section>
 <title>Converters</title>
 <content><para>This is the collection of JsonConverters that will be used during serialization and deserialization.</para>
 <para>A <codeEntityReference>T:Newtonsoft.Json.JsonConverter</codeEntityReference> allows JSON to be manually written during serialization and read during deserialization.
 This is useful for particularly complex JSON structures or for when you want to change how a type is serialized.</para>
 <para>When a JsonConverter has been added to a JsonSerializer it will be checked for every value that is being serialized/deserialized
 using its CanConvert to see if it should be used. If CanConvert returns true then the JsonConverter will be used to read or write
 the JSON for that value. Note that while a JsonConverter gives you complete control over that values JSON, many Json.NET serialization
 features are no longer available like type name and reference handling.</para>

<para>JsonConverters can be used as an argument when calling the serializer, it can be set on an object or property
using <codeEntityReference>T:Newtonsoft.Json.JsonConverterAttribute</codeEntityReference>, it be set on an object's properties or
a collection's items using <codeEntityReference>P:Newtonsoft.Json.JsonContainerAttribute.ItemConverterType</codeEntityReference>,
or a property's object properties or collection items using
<codeEntityReference>P:Newtonsoft.Json.JsonPropertyAttribute.ItemConverterType</codeEntityReference>.</para>

 <para>To create your own custom converter inherit from the JsonConverter class. Read more about the built-in JsonConverters below:</para>
<list class="bullet">
  <listItem><para><link xlink:href="DatesInJSON" /></para></listItem>
  <listItem><para><link xlink:href="ConvertingJSONandXML" /></para></listItem>
  <listItem><para><link xlink:href="CustomCreationConverter" /></para></listItem>
  <listItem><para><codeEntityReference>T:Newtonsoft.Json.Converters.StringEnumConverter</codeEntityReference></para></listItem>
</list>


</content>
</section>

<section>
 <title>ContractResolver</title>
 <content><para>Internally for every .NET type the JsonSerializer will create a contract of how the type should be serialized and deserialized,
 based on type metadata and attributes applied to the class. Specifying a custom <codeEntityReference>T:Newtonsoft.Json.Serialization.IContractResolver</codeEntityReference>
 allows the creation of contracts to be customized.</para>
 <para>Read more about Contract Resolvers here: <link xlink:href="ContractResolver" /></para>
</content>
</section>

<section>
 <title>TraceWriter</title>
 <content><para>The Json.NET serializer supports logging and debugging using the
      <codeEntityReference>T:Newtonsoft.Json.Serialization.ITraceWriter</codeEntityReference> interface.
      By assigning a trace writer you can debug what happens inside the Json.NET serializer when serializing and deserializing JSON.</para>
 <para>Read more about TraceWriters here: <link xlink:href="SerializationTracing" /></para>
</content>
</section>

<section>
 <title>Error</title>
 <content><para>The <codeEntityReference>E:Newtonsoft.Json.JsonSerializer.Error</codeEntityReference> event can catch errors during serialization and either handle the event and continue with
 serialization or let the error bubble up and be thrown to the application.</para>
 <para>Read more about error handling here: <link xlink:href="SerializationErrorHandling" /></para>
</content>
</section>
</sections>
    <relatedTopics>
      <link xlink:href="SerializationGuide" />
      <link xlink:href="SerializationAttributes" />
      <link xlink:href="DatesInJSON" />
      
      <codeEntityReference>T:Newtonsoft.Json.JsonSerializer</codeEntityReference>
      <codeEntityReference>T:Newtonsoft.Json.JsonSerializerSettings</codeEntityReference>
      <codeEntityReference>T:Newtonsoft.Json.JsonConverter</codeEntityReference>
      <codeEntityReference>T:System.Runtime.Serialization.SerializationBinder</codeEntityReference>
    </relatedTopics>
  </developerConceptualDocument>
</topic>

Commits for ChrisCompleteCodeTrunk/M3Workflow/Libraries/Json90r1/Source/Doc/SerializationSettings.aml

Diff revisions: vs.
Revision Author Commited Message
1 BBDSCHRIS picture BBDSCHRIS Wed 22 Aug, 2018 20:08:03 +0000