You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following implementations of the `ISerializer` interface is used to serialize objects into a `Stream`:
9
+
The following implementation of the `ISerializer` interface is used to serialize objects into a `Stream`:
8
10
9
-
-`XmlSerializer` makes use of the standard .NET XML serialization functionality.
10
-
-`JsonSerializer` makes use of the `System.Test.Json` serialization functionality.
11
+
-`JsonSerializer` makes use of the `System.Text.Json` serialization functionality.
11
12
12
13
## Usage
13
14
14
-
### XmlSerializer
15
-
16
-
```c#
17
-
services.AddXmlSerializer(builder=> {
18
-
builder.Options=newXmlSerializerOptions
19
-
{
20
-
};
21
-
22
-
// or
23
-
24
-
buidler.Options.option=value;
25
-
});
26
-
```
27
-
28
-
The `builder.Options` contains properties that map to [XmlWriterSettings](https://learn.microsoft.com/en-us/dotnet/api/system.xml.xmlwritersettings?view=net-8.0) as well as [XmlDictionaryReaderQuotas](https://learn.microsoft.com/en-us/dotnet/api/system.xml.xmldictionaryreaderquotas?view=net-8.0).
Deserializes the `Stream` into an `object` of the given type.
63
48
64
-
## ISerializerRootType
65
-
66
-
The `XmlSerializer` implements the `ISerializerRootType` interface which is an optional interface that serializer implementations can use that allows the developer to specify explicit object types contained within a root type.
67
-
68
-
It is recommended that you explicitly register types with the same name, but in different namespaes, that will be serialized within the same root type to avoid any conflicts later down the line.
69
-
70
-
For instance, the following two types will cause issues when used in the root `Complex` type as they both serialize to the same name and the .Net serializer cannot seem to distinguish the difference:
71
-
72
-
```c#
73
-
namespaceSerializer.v1
74
-
{
75
-
publicclassMovedEvent
76
-
{
77
-
publicstringWhere { get; set; }
78
-
}
79
-
}
80
-
81
-
namespaceSerializer.v2
82
-
{
83
-
publicclassMovedEvent
84
-
{
85
-
publicstringWhere { get; set; }
86
-
}
87
-
}
88
-
89
-
namespaceSerializer
90
-
{
91
-
publicclassComplex
92
-
{
93
-
public v1.MovedEvent { get; set; }
94
-
public v2.MovedEvent { get; set; }
95
-
}
96
-
}
97
-
```
98
-
99
-
By explicitly specifying the types the `XmlSerializer` will add a namespace that will cause the types to be correctly identified.
100
-
101
-
### AddSerializerType
102
-
103
-
```c#
104
-
voidAddSerializerType(Typeroot, Typecontained);
105
-
```
106
-
107
-
Specify the `contained` type that is used within the `root` type.
0 commit comments