-Added documentation (gasp!)
-Fixed serialization of Uri members on Silverlight/Compact Framework -Fixed serialization of JToken members -Fixed (hopefully) cache threading issues
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Advanced JSON Serialization</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">Advanced JSON Serialization</span></div>
|
||||
|
||||
<div id="content">
|
||||
<span style="color: DarkGray"> </span>
|
||||
|
||||
<p>The Json.NET serializer has a number of advanced options to alter how JSON is serialized and deserialized.</p>
|
||||
|
||||
<h3>IMappingResolver</h3>
|
||||
|
||||
<p>The <a href="./html/T_Newtonsoft_Json_Serialization_IMappingResolver.htm">IMappingResolver</a> interface provides a way to globally customize how the JsonSerializer maps JSON properties to .NET object members.</p>
|
||||
<p>Implementing the IMappingResolver interface and then assigning an instance to a JsonSerializer lets you control what object members should be serialized, how they are serialized and what they are called.</p>
|
||||
|
||||
<h4>DefaultMappingResolver</h4>
|
||||
<p>The <a href="./html/T_Newtonsoft_Json_Serialization_DefaultMappingResolver.htm">DefaultMappingResolver</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>CamelCaseMappingResolver</h4>
|
||||
<p><a href="./html/T_Newtonsoft_Json_Serialization_CamelCaseMappingResolver.htm">CamelCaseMappingResolver</a> inherits from DefaultMappingResolver 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;"> {</pre>
|
||||
|
||||
<pre style="margin: 0px;"> 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;"> Name = <span style="color: rgb(163, 21, 21);">"Widget"</span>,</pre>
|
||||
|
||||
<pre style="margin: 0px;"> Price = 9.99m,</pre>
|
||||
|
||||
<pre style="margin: 0px;"> 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;"> };</pre>
|
||||
|
||||
<pre style="margin: 0px;"> </pre>
|
||||
|
||||
<pre style="margin: 0px;"><span style="color: blue;">string</span> json = </pre>
|
||||
|
||||
<pre style="margin: 0px;"> <span style="color: rgb(43, 145, 175);">JsonConvert</span>.SerializeObject(</pre>
|
||||
|
||||
<pre style="margin: 0px;"> product,</pre>
|
||||
|
||||
<pre style="margin: 0px;"> <span style="color: rgb(43, 145, 175);">Formatting</span>.Indented,</pre>
|
||||
|
||||
<pre style="margin: 0px;"> <span style="color: blue;">new</span> <span style="color: rgb(43, 145, 175);">JsonSerializerSettings</span> { MappingResolver = <span style="color: blue;">new</span> <span style="color: rgb(43, 145, 175);">CamelCaseMappingResolver</span>() }</pre>
|
||||
|
||||
<pre style="margin: 0px;"> );</pre>
|
||||
|
||||
<pre style="margin: 0px;"> </pre>
|
||||
|
||||
<pre style="margin: 0px;"><span style="color: green;">//{</span></pre>
|
||||
|
||||
<pre style="margin: 0px;"><span style="color: green;">// "name": "Widget",</span></pre>
|
||||
|
||||
<pre style="margin: 0px;"><span style="color: green;">// "expiryDate": "\/Date(1292868060000)\/",</span></pre>
|
||||
|
||||
<pre style="margin: 0px;"><span style="color: green;">// "price": 9.99,</span></pre>
|
||||
|
||||
<pre style="margin: 0px;"><span style="color: green;">// "sizes": [</span></pre>
|
||||
|
||||
<pre style="margin: 0px;"><span style="color: green;">// "Small",</span></pre>
|
||||
|
||||
<pre style="margin: 0px;"><span style="color: green;">// "Medium",</span></pre>
|
||||
|
||||
<pre style="margin: 0px;"><span style="color: green;">// "Large"</span></pre>
|
||||
|
||||
<pre style="margin: 0px;"><span style="color: green;">// ]</span></pre>
|
||||
|
||||
<pre style="margin: 0px;"><span style="color: green;">//}</span></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="footer">
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user