Skip to content

Commit

Permalink
## Summary (#43349)
Browse files Browse the repository at this point in the history
Changed the code samples with System.Text.Json Converters (Now readonly property).

Fixes #43178, makes #43179 obsolete.
  • Loading branch information
SeppPenner authored Nov 15, 2024
1 parent 043b3c1 commit 4e51802
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@ public static void Run()
// <Serialize>
var serializeOptions = new JsonSerializerOptions
{
WriteIndented = true,
Converters =
{
new DateTimeOffsetJsonConverter()
}
WriteIndented = true
};
serializeOptions.Converters.Add(new DateTimeOffsetJsonConverter());

jsonString = JsonSerializer.Serialize(weatherForecast, serializeOptions);
// </Serialize>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ public static void Run()

Console.WriteLine("Deserialize JSON string [1, 2, 3] with custom converter, then serialize it back to JSON.");
// <Register>
var options = new JsonSerializerOptions
{
Converters = { new JsonConverterFactoryForStackOfT() },
};
var options = new JsonSerializerOptions();
options.Converters.Add(new JsonConverterFactoryForStackOfT());
// </Register>
stack = JsonSerializer.Deserialize<Stack<int>>("[1, 2, 3]", options)!;
serialized = JsonSerializer.Serialize(stack, options);
Expand Down

0 comments on commit 4e51802

Please sign in to comment.