Skip to content

Commit 57cd2b1

Browse files
committed
feat: use text.json instead Newtonsoft
1 parent baab26d commit 57cd2b1

15 files changed

+354
-220
lines changed

Storage/Bucket.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,48 @@
11
using System;
22
using System.Collections.Generic;
3-
using Newtonsoft.Json;
3+
using System.Text.Json.Serialization;
44

55
namespace Supabase.Storage
66
{
77
public class Bucket
88
{
9-
[JsonProperty("id")]
9+
[JsonPropertyName("id")]
1010
public string? Id { get; set; }
1111

12-
[JsonProperty("name")]
12+
[JsonPropertyName("name")]
1313
public string? Name { get; set; }
1414

15-
[JsonProperty("owner")]
15+
[JsonPropertyName("owner")]
1616
public string? Owner { get; set; }
1717

18-
[JsonProperty("created_at")]
18+
[JsonPropertyName("created_at")]
1919
public DateTime? CreatedAt { get; set; }
2020

21-
[JsonProperty("updated_at")]
21+
[JsonPropertyName("updated_at")]
2222
public DateTime? UpdatedAt { get; set; }
2323

2424
/// <summary>
2525
/// The visibility of the bucket. Public buckets don't require an authorization token to download objects,
2626
/// but still require a valid token for all other operations. By default, buckets are private.
2727
/// </summary>
28-
[JsonProperty("public")]
28+
[JsonPropertyName("public")]
2929
public bool Public { get; set; }
3030

3131
/// <summary>
3232
/// Specifies the file size limit that this bucket can accept during upload.
3333
///
3434
/// Expects a string value following a format like: '1kb', '50mb', '150kb', etc.
3535
/// </summary>
36-
[JsonProperty("file_size_limit", NullValueHandling = NullValueHandling.Include)]
36+
[JsonPropertyName("file_size_limit")]
3737
public string? FileSizeLimit { get; set; }
3838

3939
/// <summary>
4040
/// Specifies the allowed mime types that this bucket can accept during upload.
4141
///
4242
/// Expects a List of values such as: ['image/jpeg', 'image/png', etc]
4343
/// </summary>
44-
[JsonProperty("allowed_mime_types", NullValueHandling = NullValueHandling.Ignore)]
44+
[JsonPropertyName("allowed_mime_types")]
45+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
4546
public List<string>? AllowedMimes { get; set; }
4647
}
4748
}

Storage/BucketUpsertOptions.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System.Collections.Generic;
2-
using Newtonsoft.Json;
2+
using System.Text.Json.Serialization;
33

44
namespace Supabase.Storage
55
{
@@ -9,23 +9,24 @@ public class BucketUpsertOptions
99
/// The visibility of the bucket. Public buckets don't require an authorization token to download objects,
1010
/// but still require a valid token for all other operations. By default, buckets are private.
1111
/// </summary>
12-
[JsonProperty("public")]
12+
[JsonPropertyName("public")]
1313
public bool Public { get; set; } = false;
1414

1515
/// <summary>
1616
/// Specifies the file size limit that this bucket can accept during upload.
1717
///
1818
/// Expects a string value following a format like: '1kb', '50mb', '150kb', etc.
1919
/// </summary>
20-
[JsonProperty("file_size_limit", NullValueHandling = NullValueHandling.Include)]
20+
[JsonPropertyName("file_size_limit")]
2121
public string? FileSizeLimit { get; set; }
2222

2323
/// <summary>
2424
/// Specifies the allowed mime types that this bucket can accept during upload.
2525
///
2626
/// Expects a List of values such as: ['image/jpeg', 'image/png', etc]
2727
/// </summary>
28-
[JsonProperty("allowed_mime_types", NullValueHandling = NullValueHandling.Ignore)]
28+
[JsonPropertyName("allowed_mime_types")]
29+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
2930
public List<string>? AllowedMimes { get; set; }
3031
}
3132
}

Storage/CreateSignedUrlResponse.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
1-
using Newtonsoft.Json;
1+
using System.Text.Json.Serialization;
22

33
namespace Supabase.Storage
44
{
5+
/// <summary>
6+
/// Represents the response received when creating a signed URL for file access through Supabase Storage.
7+
/// </summary>
58
public class CreateSignedUrlResponse
69
{
7-
[JsonProperty("signedURL")]
10+
/// <summary>
11+
/// Represents the signed URL returned as part of a response when requesting access to a file
12+
/// stored in Supabase Storage. This URL can be used to access the file directly with
13+
/// the defined expiration and optional transformations or download options applied.
14+
/// </summary>
15+
[JsonPropertyName("signedURL")]
816
public string? SignedUrl { get; set; }
917
}
1018

19+
/// <summary>
20+
/// Represents the extended response received when creating multiple signed URLs
21+
/// for file access through Supabase Storage. In addition to the signed URL, it includes
22+
/// the associated file path.
23+
/// </summary>
1124
public class CreateSignedUrlsResponse: CreateSignedUrlResponse
1225
{
13-
[JsonProperty("path")]
26+
/// <summary>
27+
/// Represents the file path associated with a signed URL in the response.
28+
/// This property indicates the specific file path for which the signed URL
29+
/// was generated, allowing identification of the file within the storage bucket.
30+
/// </summary>
31+
[JsonPropertyName("path")]
1432
public string? Path { get; set; }
1533
}
1634
}

Storage/DownloadOptions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
using Newtonsoft.Json;
2-
31
namespace Supabase.Storage
42
{
3+
/// <summary>
4+
/// Represents options used when downloading files from storage.
5+
/// </summary>
56
public class DownloadOptions
67
{
78
/// <summary>

Storage/Extensions/HttpClientProgress.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Net.Http;
5+
using System.Text.Json;
56
using System.Threading;
67
using System.Threading.Tasks;
78
using BirdMessenger;
89
using BirdMessenger.Collections;
9-
using Newtonsoft.Json;
1010
using Supabase.Storage.Exceptions;
1111

1212
namespace Supabase.Storage.Extensions
@@ -45,7 +45,10 @@ public static async Task<MemoryStream> DownloadDataAsync(
4545
if (!response.IsSuccessStatusCode)
4646
{
4747
var content = await response.Content.ReadAsStringAsync();
48-
var errorResponse = JsonConvert.DeserializeObject<ErrorResponse>(content);
48+
var errorResponse = JsonSerializer.Deserialize<ErrorResponse>(
49+
content,
50+
Helpers.JsonOptions
51+
);
4952
var e = new SupabaseStorageException(errorResponse?.Message ?? content)
5053
{
5154
Content = content,
@@ -175,12 +178,15 @@ public static async Task<HttpResponseMessage> UploadAsync(
175178
}
176179
}
177180

178-
var response = await client.PostAsync(uri, content, cancellationToken);
181+
var response = await client.PostAsync(uri, content, cancellationToken);
179182

180183
if (!response.IsSuccessStatusCode)
181184
{
182185
var httpContent = await response.Content.ReadAsStringAsync();
183-
var errorResponse = JsonConvert.DeserializeObject<ErrorResponse>(httpContent);
186+
var errorResponse = JsonSerializer.Deserialize<ErrorResponse>(
187+
httpContent,
188+
Helpers.JsonOptions
189+
);
184190
var e = new SupabaseStorageException(errorResponse?.Message ?? httpContent)
185191
{
186192
Content = httpContent,
@@ -301,7 +307,10 @@ private static async Task<HttpResponseMessage> ResumableUploadAsync(
301307
return responsePatch.OriginResponseMessage;
302308

303309
var httpContent = await responsePatch.OriginResponseMessage.Content.ReadAsStringAsync();
304-
var errorResponse = JsonConvert.DeserializeObject<ErrorResponse>(httpContent);
310+
var errorResponse = JsonSerializer.Deserialize<ErrorResponse>(
311+
httpContent,
312+
Helpers.JsonOptions
313+
);
305314
var e = new SupabaseStorageException(errorResponse?.Message ?? httpContent)
306315
{
307316
Content = httpContent,

Storage/FileObject.cs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3-
using Newtonsoft.Json;
3+
using System.Text.Json.Serialization;
44

55
namespace Supabase.Storage
66
{
@@ -10,32 +10,23 @@ public class FileObject
1010
/// Flag representing if this object is a folder, all properties will be null but the name
1111
/// </summary>
1212
public bool IsFolder => !string.IsNullOrEmpty(Name) && Id == null && CreatedAt == null && UpdatedAt == null;
13-
14-
[JsonProperty("name")]
15-
public string? Name { get; set; }
1613

17-
[JsonProperty("bucket_id")]
18-
public string? BucketId { get; set; }
14+
[JsonPropertyName("name")] public string? Name { get; set; }
1915

20-
[JsonProperty("owner")]
21-
public string? Owner { get; set; }
16+
[JsonPropertyName("bucket_id")] public string? BucketId { get; set; }
2217

23-
[JsonProperty("id")]
24-
public string? Id { get; set; }
18+
[JsonPropertyName("owner")] public string? Owner { get; set; }
2519

26-
[JsonProperty("updated_at")]
27-
public DateTime? UpdatedAt { get; set; }
20+
[JsonPropertyName("id")] public string? Id { get; set; }
2821

29-
[JsonProperty("created_at")]
30-
public DateTime? CreatedAt { get; set; }
22+
[JsonPropertyName("updated_at")] public DateTime? UpdatedAt { get; set; }
3123

32-
[JsonProperty("last_accessed_at")]
33-
public DateTime? LastAccessedAt { get; set; }
24+
[JsonPropertyName("created_at")] public DateTime? CreatedAt { get; set; }
3425

35-
[JsonProperty("metadata")]
36-
public Dictionary<string, object> MetaData = new Dictionary<string, object>();
26+
[JsonPropertyName("last_accessed_at")] public DateTime? LastAccessedAt { get; set; }
3727

38-
[JsonProperty("buckets")]
39-
public Bucket? Buckets { get; set; }
28+
[JsonPropertyName("metadata")] public Dictionary<string, object> MetaData = new Dictionary<string, object>();
29+
30+
[JsonPropertyName("buckets")] public Bucket? Buckets { get; set; }
4031
}
41-
}
32+
}

Storage/FileObjectV2.cs

Lines changed: 65 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,92 @@
11
using System;
22
using System.Collections.Generic;
3-
using Newtonsoft.Json;
3+
using System.Text.Json.Serialization;
44

55
namespace Supabase.Storage
66
{
7+
/// <summary>
8+
/// Represents a file object in Supabase Storage with its associated metadata and properties.
9+
/// This class is used for version 2 of the Storage API.
10+
/// </summary>
711
public class FileObjectV2
812
{
913

10-
[JsonProperty("id")]
14+
/// <summary>
15+
/// The unique identifier of the file.
16+
/// </summary>
17+
[JsonPropertyName("id")]
1118
public string Id { get; set; }
12-
13-
[JsonProperty("version")]
19+
20+
/// <summary>
21+
/// The version of the file.
22+
/// </summary>
23+
[JsonPropertyName("version")]
1424
public string Version { get; set; }
15-
16-
[JsonProperty("name")]
25+
26+
/// <summary>
27+
/// The name of the file.
28+
/// </summary>
29+
[JsonPropertyName("name")]
1730
public string? Name { get; set; }
1831

19-
[JsonProperty("bucket_id")]
32+
/// <summary>
33+
/// The identifier of the bucket containing the file.
34+
/// </summary>
35+
[JsonPropertyName("bucket_id")]
2036
public string? BucketId { get; set; }
2137

22-
[JsonProperty("updated_at")]
38+
/// <summary>
39+
/// The timestamp when the file was last updated.
40+
/// </summary>
41+
[JsonPropertyName("updated_at")]
2342
public DateTime? UpdatedAt { get; set; }
2443

25-
[JsonProperty("created_at")]
44+
/// <summary>
45+
/// The timestamp when the file was created.
46+
/// </summary>
47+
[JsonPropertyName("created_at")]
2648
public DateTime? CreatedAt { get; set; }
2749

28-
[JsonProperty("last_accessed_at")]
50+
/// <summary>
51+
/// The timestamp when the file was last accessed.
52+
/// </summary>
53+
[JsonPropertyName("last_accessed_at")]
2954
public DateTime? LastAccessedAt { get; set; }
30-
31-
[JsonProperty("size")]
55+
56+
/// <summary>
57+
/// The size of the file in bytes.
58+
/// </summary>
59+
[JsonPropertyName("size")]
3260
public int? Size { get; set; }
33-
34-
[JsonProperty("cache_control")]
61+
62+
/// <summary>
63+
/// The cache control directives for the file.
64+
/// </summary>
65+
[JsonPropertyName("cache_control")]
3566
public string? CacheControl { get; set; }
36-
37-
[JsonProperty("content_type")]
67+
68+
/// <summary>
69+
/// The MIME type of the file.
70+
/// </summary>
71+
[JsonPropertyName("content_type")]
3872
public string? ContentType { get; set; }
39-
40-
[JsonProperty("etag")]
73+
74+
/// <summary>
75+
/// The ETag of the file for caching purposes.
76+
/// </summary>
77+
[JsonPropertyName("etag")]
4178
public string? Etag { get; set; }
42-
43-
[JsonProperty("last_modified")]
79+
80+
/// <summary>
81+
/// The timestamp when the file was last modified.
82+
/// </summary>
83+
[JsonPropertyName("last_modified")]
4484
public DateTime? LastModified { get; set; }
45-
46-
[JsonProperty("metadata")]
85+
86+
/// <summary>
87+
/// The custom metadata associated with the file.
88+
/// </summary>
89+
[JsonPropertyName("metadata")]
4790
public Dictionary<string, string>? Metadata { get; set; }
4891
}
4992
}

0 commit comments

Comments
 (0)