-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP Migrating from Newtonsoft.Json to System.Text.Json
- Loading branch information
Showing
20 changed files
with
422 additions
and
298 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,53 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
namespace Supabase.Postgrest.Converters | ||
{ | ||
|
||
/// <inheritdoc /> | ||
public class IntArrayConverter : JsonConverter | ||
public class IntArrayConverter : JsonConverter<List<int>> | ||
{ | ||
/// <inheritdoc /> | ||
public override bool CanConvert(Type objectType) | ||
public override bool CanConvert(Type typeToConvert) | ||
{ | ||
throw new NotImplementedException(); | ||
return typeToConvert == typeof(List<int>); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override bool CanRead => false; | ||
|
||
/// <inheritdoc /> | ||
public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) | ||
public override List<int>? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
throw new NotImplementedException(); | ||
if (reader.TokenType != JsonTokenType.StartArray) | ||
{ | ||
throw new JsonException("Expected start of array."); | ||
} | ||
|
||
var list = new List<int>(); | ||
|
||
while (reader.Read()) | ||
{ | ||
if (reader.TokenType == JsonTokenType.EndArray) | ||
{ | ||
return list; | ||
} | ||
|
||
if (reader.TokenType == JsonTokenType.Number) | ||
{ | ||
list.Add(reader.GetInt32()); | ||
} | ||
else | ||
{ | ||
throw new JsonException($"Unexpected token type: {reader.TokenType}"); | ||
} | ||
} | ||
|
||
throw new JsonException("Unexpected end of JSON."); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) | ||
public override void Write(Utf8JsonWriter writer, List<int> value, JsonSerializerOptions options) | ||
{ | ||
if (value is List<int> list) | ||
{ | ||
writer.WriteValue($"{{{string.Join(",", list)}}}"); | ||
} | ||
writer.WriteStringValue($"{{{string.Join(",", value)}}}"); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.