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
Copy file name to clipboardExpand all lines: README.md
+41-10Lines changed: 41 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,16 +4,48 @@
4
4
PM> Install-Package Shuttle.Core.Serialization
5
5
```
6
6
7
-
An implementation of the `ISerializer` interface is used to serialize objects into a `Stream`.
7
+
The following implementations of the `ISerializer` interface is used to serialize objects into a `Stream`:
8
8
9
-
The `DefaultSerializer` makes use of the standard .NET xml serialization functionality.
9
+
-`XmlSerializer` makes use of the standard .NET XML serialization functionality.
10
+
-`JsonSerializer` makes use of the `System.Test.Json` serialization functionality.
11
+
12
+
## Usage
13
+
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
+
### JsonSerializer
29
+
30
+
```c#
31
+
services.AddJsonSerializer(builder=> {
32
+
builder.Options=newJsonSerializerOptions
33
+
{
34
+
};
35
+
36
+
// or
37
+
38
+
buidler.Options.option=value;
39
+
});
40
+
```
41
+
42
+
The `builder.Options` is of type [JsonSerializerOptions](https://docs.microsoft.com/en-us/dotnet/api/system.text.json.jsonserializeroptions?view=net-6.0).
10
43
11
44
## Methods
12
45
13
46
### Serialize
14
47
15
48
```c#
16
-
StreamSerialize(objectmessage);
17
49
Task<Stream>SerializeAsync(objectmessage);
18
50
```
19
51
@@ -22,17 +54,16 @@ Returns the message `object` as a `Stream`.
Deserializes the `Stream` into an `object` of the given type.
30
61
31
-
# ISerializerRootType
62
+
##ISerializerRootType
32
63
33
-
The `ISerializerRootType` interface is an optional interface that serializer implementations can use that allows the developer to specify explicit object types contained within a root type.
64
+
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.
34
65
35
-
The `DefaultSerializer` implements this interface and 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.
66
+
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.
36
67
37
68
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:
38
69
@@ -63,12 +94,12 @@ namespace Serializer
63
94
}
64
95
```
65
96
66
-
By explicitly specifying the types the `DefaultSerializer` will add a namespace that will cause the types to be correctly identified.
97
+
By explicitly specifying the types the `XmlSerializer` will add a namespace that will cause the types to be correctly identified.
67
98
68
-
## AddSerializerType
99
+
###AddSerializerType
69
100
70
101
```c#
71
102
voidAddSerializerType(Typeroot, Typecontained);
72
103
```
73
104
74
-
Specify the `contained`tpe that is used within te`root` type somewhere.
105
+
Specify the `contained`type that is used within the`root` type.
0 commit comments