1
<?xml version="1.0" encoding="utf-8"?>
2
<topic id="ContractResolver" revisionNumber="1">
3
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
6
<para>Optional summary abstract</para>
10
<para>The <codeEntityReference>T:Newtonsoft.Json.Serialization.IContractResolver</codeEntityReference>
11
interface provides a way to customize how the
12
JsonSerializer serializes and deserializes .NET objects to JSON without placing attributes on your classes.
14
<para>Anything that can be set on an object, collection, property, etc, using attributes or methods to control serialization
15
can also be set using an IContractResolver.</para>
17
<!-- Add one or more top-level section elements. These are collapsible.
18
If using <autoOutline />, add an address attribute to identify it
19
and specify a title so that it can be jumped to with a hyperlink. -->
21
<title>DefaultContractResolver</title>
23
<!-- Uncomment this to create a sub-section outline
25
<para>The <codeEntityReference>T:Newtonsoft.Json.Serialization.DefaultContractResolver</codeEntityReference>
26
is the default resolver used by the
27
serializer. It provides many avenues of extensibility in the form of
28
virtual methods that can be overriden.</para>
32
<title>CamelCasePropertyNamesContractResolver</title>
34
<!-- Uncomment this to create a sub-section outline
36
<para><codeEntityReference>T:Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver</codeEntityReference>
37
inherits from DefaultContractResolver and simply overrides the JSON
38
property name to be written in <externalLink>
39
<linkText>camelcase</linkText>
40
<linkUri>http://en.wikipedia.org/wiki/CamelCase</linkUri>
41
<linkTarget>_blank</linkTarget>
42
</externalLink>.</para>
44
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\SerializationTests.cs" region="ContractResolver" title="ContractResolver" />
48
<title>Custom IContractResolver Examples</title>
50
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\PerformanceTests.cs" region="JsonConverterContractResolver" title="Use JsonConverter with IContractResolver" />
52
<para>This example sets a <codeEntityReference>T:Newtonsoft.Json.JsonConverter</codeEntityReference> for a type
53
using an IContractResolver. Using a contract resolver here is useful because DateTime is not your own type and it is not possible to place a JsonConverterAttribute on it.</para>
55
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\ConditionalPropertiesTests.cs" region="ShouldSerializeContractResolver" title="Conditional properties with IContractResolver" />
57
<para>This example sets up <externalLink>
58
<linkText>conditional serialization for a property</linkText>
59
<linkUri>ConditionalProperties.htm</linkUri>
60
<linkTarget>_self</linkTarget>
61
</externalLink> using an IContractResolver. This is useful if you want to conditional serialize a property but don't want to add additional methods to your type.</para>
65
<codeEntityReference>T:Newtonsoft.Json.Serialization.IContractResolver</codeEntityReference>
66
<codeEntityReference>T:Newtonsoft.Json.Serialization.DefaultContractResolver</codeEntityReference>
67
<codeEntityReference>T:Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver</codeEntityReference>
69
</developerConceptualDocument>
b'\\ No newline at end of file'