Skip to content

Commit 4a5dfe7

Browse files
Updates the README for the new improvements.
1 parent 10b29f1 commit 4a5dfe7

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

README.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,31 @@ public void Serialization()
116116
And when an exception is occured, the exception message contains the JSON path of the property which is error:
117117
![Pretty exception](https://raw.githubusercontent.com/PosInformatique/PosInformatique.FluentAssertions.Json/main/docs/PrettyExceptionSample.png)
118118

119+
Since the version 1.6.0 it is possible to use a [raw string literal](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/raw-string)
120+
with a JSON content in the string:
121+
122+
```csharp
123+
[Fact]
124+
public void Serialization()
125+
{
126+
var customer = new Customer()
127+
{
128+
Id = 1234,
129+
Name = "Gilles TOURREAU",
130+
Gender = Gender.Male,
131+
};
132+
133+
customer.Should().BeJsonSerializableInto(
134+
"""
135+
{
136+
"id": 1234,
137+
"name": "Gilles TOURREAU",
138+
"gender": 100
139+
}
140+
""");
141+
}
142+
```
143+
119144
### Test the deserialization of a JSON object to a .NET Object
120145
You can in the same way test the deserialization JSON object into a .NET object.
121146

@@ -139,7 +164,32 @@ public void Deserialization()
139164
}
140165
```
141166

142-
## Test polymorphisme serialization with property discriminator
167+
Since the version 1.6.0 it is possible to use a [raw string literal](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/raw-string)
168+
with a JSON string content as input of the `Should()` to assert:
169+
170+
```
171+
[Fact]
172+
public void Deserialization()
173+
{
174+
var json =
175+
"""
176+
{
177+
"id": 1234,
178+
"name": "Gilles TOURREAU",
179+
"gender": 100
180+
}
181+
""";
182+
183+
json.Should().BeJsonDeserializableInto(new Customer()
184+
{
185+
Id = 1234,
186+
Name = "Gilles TOURREAU",
187+
Gender = Gender.Male,
188+
});
189+
}
190+
```
191+
192+
## Test polymorphism serialization with property discriminator
143193
With the .NET 7.0 version of the `System.Text.Json` it is possible to serialize and deserialize JSON object
144194
with property discriminators for polymorphism scenario
145195
(See the [How to serialize properties of derived classes with System.Text.Json](https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/polymorphism?pivots=dotnet-7-0))

0 commit comments

Comments
 (0)