forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds deserialization support for JsonDocument
This change adds support to `System.Text.Json` for deserializing `JsonDocument`. Specifically, an internal converter `JsonDocumentConverter` is added to the default converter dictionary. I have created a basic test, but I feel more could be done here, and it may not be in the right file/class - some guidance would be helpful here. Fixes dotnet#1573
- Loading branch information
1 parent
4e179eb
commit fdbea3a
Showing
4 changed files
with
31 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...em.Text.Json/src/System/Text/Json/Serialization/Converters/Value/JsonDocumentConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
namespace System.Text.Json.Serialization.Converters | ||
{ | ||
internal sealed class JsonDocumentConverter : JsonConverter<JsonDocument> | ||
{ | ||
public override JsonDocument Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
return JsonDocument.ParseValue(ref reader); | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, JsonDocument value, JsonSerializerOptions options) | ||
{ | ||
value.WriteTo(writer); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters