File: ContractResolver.html

package info (click to toggle)
mono 4.6.2.7+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 778,148 kB
  • ctags: 914,052
  • sloc: cs: 5,779,509; xml: 2,773,713; ansic: 432,645; sh: 14,749; makefile: 12,361; perl: 2,488; python: 1,434; cpp: 849; asm: 531; sql: 95; sed: 16; php: 1
file content (92 lines) | stat: -rw-r--r-- 5,366 bytes parent folder | download | duplicates (2)
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
<html>
  
  <head>
    <title>Contract Resolver</title>
    <link href="styles.css" rel="stylesheet" type="text/css" />
    <link href="custom.css" rel="stylesheet" type="text/css" />
  </head>
  
  <body>
    
    <div id="control">
      <span class="productTitle">Json.NET - Quick Starts & API Documentation</span><br />
        <span class="topicTitle">Contract Resolvers</span></div>

    <div id="content">
      <span style="color: DarkGray"> </span>
    

	<p>The <a href="./html/T_Newtonsoft_Json_Serialization_IContractResolver.htm">IContractResolver</a> interface provides a way to customize how the JsonSerializer serializes and deserializes .NET objects to JSON.</p>
	<p>Implementing the IContractResolver interface and then assigning an instance to a JsonSerializer lets you control 
        whether the object is serialized as a JSON object or JSON array, what object members should be serialized, how they are serialized and what they are called.</p>
	
	<h4>DefaultContractResolver</h4>
	<p>The <a href="./html/T_Newtonsoft_Json_Serialization_DefaultContractResolver.htm">DefaultContractResolver</a> is the default resolver used by the serializer. It provides many avenues of extensibility in the form of virtual methods that can be overriden.</p>
	
	<h4>CamelCasePropertyNamesContractResolver</h4>
	<p><a href="./html/T_Newtonsoft_Json_Serialization_CamelCasePropertyNamesContractResolver.htm">CamelCasePropertyNamesContractResolver</a> inherits from DefaultContractResolver and simply overrides the JSON property name to be written in <a href="http://en.wikipedia.org/wiki/CamelCase" target="_blank">camelcase</a>.</p>

 <div class="overflowpanel">   <div class="code">     <div style="font-family: courier new; color: black; font-size: 10pt;">       <pre style="margin: 0px;"><span style="color: rgb(43, 145, 175);">Product</span> product = <span style="color: blue;">new</span> <span style="color: rgb(43, 145, 175);">Product</span></pre>

      <pre style="margin: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</pre>

      <pre style="margin: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ExpiryDate = <span style="color: blue;">new</span> <span style="color: rgb(43, 145, 175);">DateTime</span>(2010, 12, 20, 18, 1, 0, <span style="color: rgb(43, 145, 175);">DateTimeKind</span>.Utc),</pre>

      <pre style="margin: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Name = <span style="color: rgb(163, 21, 21);">"Widget"</span>,</pre>

      <pre style="margin: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Price = 9.99m,</pre>

      <pre style="margin: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sizes = <span style="color: blue;">new</span>[] {<span style="color: rgb(163, 21, 21);">"Small"</span>, <span style="color: rgb(163, 21, 21);">"Medium"</span>, <span style="color: rgb(163, 21, 21);">"Large"</span>}</pre>

      <pre style="margin: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };</pre>

      <pre style="margin: 0px;">&nbsp;</pre>

      <pre style="margin: 0px;"><span style="color: blue;">string</span> json = </pre>

      <pre style="margin: 0px;">&nbsp; <span style="color: rgb(43, 145, 175);">JsonConvert</span>.SerializeObject(</pre>

      <pre style="margin: 0px;">&nbsp;&nbsp;&nbsp; product,</pre>

      <pre style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: rgb(43, 145, 175);">Formatting</span>.Indented,</pre>

      <pre style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">new</span> <span style="color: rgb(43, 145, 175);">JsonSerializerSettings</span> { ContractResolver = <span style="color: blue;">new</span> <span style="color: rgb(43, 145, 175);">CamelCasePropertyNamesContractResolver</span>() }</pre>

      <pre style="margin: 0px;">&nbsp; );</pre>

      <pre style="margin: 0px;">&nbsp;</pre>

      <pre style="margin: 0px;"><span style="color: green;">//{</span></pre>

      <pre style="margin: 0px;"><span style="color: green;">//&nbsp; "name": "Widget",</span></pre>

      <pre style="margin: 0px;"><span style="color: green;">//&nbsp; "expiryDate": "\/Date(1292868060000)\/",</span></pre>

      <pre style="margin: 0px;"><span style="color: green;">//&nbsp; "price": 9.99,</span></pre>

      <pre style="margin: 0px;"><span style="color: green;">//&nbsp; "sizes": [</span></pre>

      <pre style="margin: 0px;"><span style="color: green;">//&nbsp;&nbsp;&nbsp; "Small",</span></pre>

      <pre style="margin: 0px;"><span style="color: green;">//&nbsp;&nbsp;&nbsp; "Medium",</span></pre>

      <pre style="margin: 0px;"><span style="color: green;">//&nbsp;&nbsp;&nbsp; "Large"</span></pre>

      <pre style="margin: 0px;"><span style="color: green;">//&nbsp; ]</span></pre>

      <pre style="margin: 0px;"><span style="color: green;">//}</span></pre>
    </div>
  </div>
</div>


      <div id="footer">


    
        </div>      
    </div>

  </body>

</html>