-
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Review feedback: use base class instead of static helper
- Loading branch information
Bart Koelman
committed
Sep 17, 2021
1 parent
e655fa6
commit 2e0c811
Showing
6 changed files
with
63 additions
and
68 deletions.
There are no files selected for viewing
37 changes: 0 additions & 37 deletions
37
src/JsonApiDotNetCore/Serialization/JsonConverterSupport.cs
This file was deleted.
Oops, something went wrong.
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
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
35 changes: 35 additions & 0 deletions
35
src/JsonApiDotNetCore/Serialization/JsonObjectConverter.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,35 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace JsonApiDotNetCore.Serialization | ||
{ | ||
public abstract class JsonObjectConverter<TObject> : JsonConverter<TObject> | ||
{ | ||
protected static TValue ReadSubTree<TValue>(ref Utf8JsonReader reader, JsonSerializerOptions options) | ||
{ | ||
if (typeof(TValue) != typeof(object) && options?.GetConverter(typeof(TValue)) is JsonConverter<TValue> converter) | ||
{ | ||
return converter.Read(ref reader, typeof(TValue), options); | ||
} | ||
|
||
return JsonSerializer.Deserialize<TValue>(ref reader, options); | ||
} | ||
|
||
protected static void WriteSubTree<TValue>(Utf8JsonWriter writer, TValue value, JsonSerializerOptions options) | ||
{ | ||
if (typeof(TValue) != typeof(object) && options?.GetConverter(typeof(TValue)) is JsonConverter<TValue> converter) | ||
{ | ||
converter.Write(writer, value, options); | ||
} | ||
else | ||
{ | ||
JsonSerializer.Serialize(writer, value, options); | ||
} | ||
} | ||
|
||
protected static JsonException GetEndOfStreamError() | ||
{ | ||
return new("Unexpected end of JSON stream."); | ||
} | ||
} | ||
} |