Skip to content

Commit 8159279

Browse files
committed
feat: migrate to newtonsoft json
Signed-off-by: STRRL <im@strrl.dev>
1 parent 2d42325 commit 8159279

15 files changed

+79
-63
lines changed

reddio-csharp/crypto-csharp.sln.DotSettings.user

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2-
<s:String x:Key="/Default/Environment/Highlighting/HighlightingSourceSnapshotLocation/@EntryValue">/home/strrl/.cache/JetBrains/Rider2022.2/resharper-host/temp/Rider/vAny/CoverageData/_crypto-csharp.-1419227475/Snapshot/snapshot.utdcvr</s:String>
2+
33
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=4123da31_002D1ab1_002D4c5c_002Dbf63_002D710bd276e207/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" Name="ReddioClientTests" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
44
&lt;TestAncestor&gt;
55
&lt;TestId&gt;xUnit::94DEE188-2D3D-4107-872F-713AB912A6DD::net6.0::Reddio.Tests.Api.V1.ReddioClientTests&lt;/TestId&gt;

reddio-csharp/reddio.api/V1/Rest/GetAssetIdMessage.cs

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

33
namespace Reddio.Api.V1.Rest
44
{
55
public class GetAssetIdMessage
66
{
7-
[JsonPropertyName("contract_address")] public string ContractAddress { get; set; }
8-
[JsonPropertyName("type")] public string Type { get; set; }
9-
[JsonPropertyName("token_id")] public string TokenId { get; set; }
7+
[JsonProperty("contract_address")] public string ContractAddress { get; set; }
8+
[JsonProperty("type")] public string Type { get; set; }
9+
[JsonProperty("token_id")] public string TokenId { get; set; }
1010

1111
public GetAssetIdMessage()
1212
{

reddio-csharp/reddio.api/V1/Rest/GetAssetIdResponse.cs

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

33
namespace Reddio.Api.V1.Rest
44
{
55
public class GetAssetIdResponse
66
{
7-
[JsonPropertyName("asset_id")] public string AssetId { get; set; }
7+
[JsonProperty("asset_id")] public string AssetId { get; set; }
88

99
public GetAssetIdResponse()
1010
{

reddio-csharp/reddio.api/V1/Rest/GetNonceMessage.cs

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

33
namespace Reddio.Api.V1.Rest
44
{
55
public class GetNonceMessage
66
{
7-
[JsonPropertyName("stark_key")] public string StarkKey { get; set; }
7+
[JsonProperty("stark_key")] public string StarkKey { get; set; }
88

99
public GetNonceMessage()
1010
{

reddio-csharp/reddio.api/V1/Rest/GetNonceResponse.cs

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

44
namespace Reddio.Api.V1.Rest
55
{
@@ -14,6 +14,6 @@ public GetNonceResponse(long nonce)
1414
Nonce = nonce;
1515
}
1616

17-
[JsonPropertyName("nonce")] public Int64 Nonce { get; set; }
17+
[JsonProperty("nonce")] public Int64 Nonce { get; set; }
1818
}
1919
}

reddio-csharp/reddio.api/V1/Rest/GetRecordMessage.cs

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

44
namespace Reddio.Api.V1.Rest
55
{
@@ -15,7 +15,7 @@ public GetRecordMessage(string starkKey, long sequenceId)
1515
SequenceId = sequenceId;
1616
}
1717

18-
[JsonPropertyName("stark_key")] public string StarkKey { get; set; }
19-
[JsonPropertyName("sequence_id")] public Int64 SequenceId { get; set; }
18+
[JsonProperty("stark_key")] public string StarkKey { get; set; }
19+
[JsonProperty("sequence_id")] public Int64 SequenceId { get; set; }
2020
}
2121
}

reddio-csharp/reddio.api/V1/Rest/GetRecordResponse.cs

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

55
namespace Reddio.Api.V1.Rest
66
{
@@ -40,19 +40,19 @@ public SequenceRecord()
4040
{
4141
}
4242

43-
[JsonPropertyName("amount")] public string Amount { get; set; }
44-
[JsonPropertyName("asset_id")] public string AssetId { get; set; }
45-
[JsonPropertyName("asset_name")] public string AssetName { get; set; }
46-
[JsonPropertyName("asset_type")] public string AssetType { get; set; }
47-
[JsonPropertyName("contract_address")] public string ContractAddress { get; set; }
48-
[JsonPropertyName("display_value")] public string DisplayValue { get; set; }
49-
[JsonPropertyName("from")] public string From { get; set; }
50-
[JsonPropertyName("record_type")] public int RecordType { get; set; }
51-
[JsonPropertyName("sequence_id")] public Int64 SequenceId { get; set; }
52-
[JsonPropertyName("stark_key")] public string StarkKey { get; set; }
53-
[JsonPropertyName("status")] public int Status { get; set; }
54-
[JsonPropertyName("time")] public Int64 Time { get; set; }
55-
[JsonPropertyName("to")] public string To { get; set; }
56-
[JsonPropertyName("token_id")] public string TokenId { get; set; }
43+
[JsonProperty("amount")] public string Amount { get; set; }
44+
[JsonProperty("asset_id")] public string AssetId { get; set; }
45+
[JsonProperty("asset_name")] public string AssetName { get; set; }
46+
[JsonProperty("asset_type")] public string AssetType { get; set; }
47+
[JsonProperty("contract_address")] public string ContractAddress { get; set; }
48+
[JsonProperty("display_value")] public string DisplayValue { get; set; }
49+
[JsonProperty("from")] public string From { get; set; }
50+
[JsonProperty("record_type")] public int RecordType { get; set; }
51+
[JsonProperty("sequence_id")] public Int64 SequenceId { get; set; }
52+
[JsonProperty("stark_key")] public string StarkKey { get; set; }
53+
[JsonProperty("status")] public int Status { get; set; }
54+
[JsonProperty("time")] public Int64 Time { get; set; }
55+
[JsonProperty("to")] public string To { get; set; }
56+
[JsonProperty("token_id")] public string TokenId { get; set; }
5757
}
5858
}

reddio-csharp/reddio.api/V1/Rest/GetVaultIdMessage.cs

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

44
namespace Reddio.Api.V1.Rest
55
{
66
public class GetVaultIdMessage
77
{
8-
[JsonPropertyName("asset_id")] public string AssetId { get; set; }
9-
[JsonPropertyName("stark_keys")] public List<string> StarkKeys { get; set; }
8+
[JsonProperty("asset_id")] public string AssetId { get; set; }
9+
[JsonProperty("stark_keys")] public List<string> StarkKeys { get; set; }
1010

1111
public GetVaultIdMessage()
1212
{

reddio-csharp/reddio.api/V1/Rest/GetVaultIdResponse.cs

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

44
namespace Reddio.Api.V1.Rest
55
{
@@ -14,6 +14,6 @@ public GetVaultIdResponse(List<string> vaultIds)
1414
VaultIds = vaultIds;
1515
}
1616

17-
[JsonPropertyName("vault_ids")] public List<string> VaultIds { get; set; }
17+
[JsonProperty("vault_ids")] public List<string> VaultIds { get; set; }
1818
}
1919
}

reddio-csharp/reddio.api/V1/Rest/ReddioRestClient.cs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using System;
22
using System.Net.Http;
33
using System.Net.Http.Headers;
4-
using System.Net.Http.Json;
54
using System.Text;
65
using System.Threading.Tasks;
6+
using Newtonsoft.Json;
77

88
namespace Reddio.Api.V1.Rest
99
{
@@ -27,13 +27,26 @@ private static HttpClient HttpClientWithReddioUA()
2727
return client;
2828
}
2929

30+
private static HttpContent JsonStringContent<T>(T payload)
31+
{
32+
var jsonString = JsonConvert.SerializeObject(payload);
33+
var content = new StringContent(jsonString, Encoding.UTF8, "application/json");
34+
return content;
35+
}
36+
37+
private static async Task<T> ReadAsJsonAsync<T>(HttpResponseMessage response)
38+
{
39+
var responseContent = await response.Content.ReadAsStringAsync();
40+
return JsonConvert.DeserializeObject<T>(responseContent)!;
41+
}
42+
3043
public async Task<ResponseWrapper<TransferResponse>> Transfer(TransferMessage transferMessage)
3144
{
3245
var endpoint = $"{_baseEndpoint}/v1/transfers";
3346
var client = HttpClientWithReddioUA();
34-
var response = await client.PostAsJsonAsync(endpoint, transferMessage);
47+
var response = await client.PostAsync(endpoint, JsonStringContent(transferMessage));
3548
response.EnsureSuccessStatusCode();
36-
var result = await response.Content.ReadFromJsonAsync<ResponseWrapper<TransferResponse>>();
49+
var result = await ReadAsJsonAsync<ResponseWrapper<TransferResponse>>(response);
3750
return result!;
3851
}
3952

@@ -43,7 +56,7 @@ public async Task<ResponseWrapper<GetNonceResponse>> GetNonce(GetNonceMessage ge
4356
var client = HttpClientWithReddioUA();
4457
var response = await client.GetAsync(endpoint);
4558
response.EnsureSuccessStatusCode();
46-
var result = await response.Content.ReadFromJsonAsync<ResponseWrapper<GetNonceResponse>>();
59+
var result = await ReadAsJsonAsync<ResponseWrapper<GetNonceResponse>>(response);
4760
return result!;
4861
}
4962

@@ -55,7 +68,7 @@ public async Task<ResponseWrapper<GetAssetIdResponse>> GetAssetId(GetAssetIdMess
5568
request.Content = new StringContent("", Encoding.UTF8, "application/json");
5669
var client = HttpClientWithReddioUA();
5770
var response = await client.SendAsync(request);
58-
var result = await response.Content.ReadFromJsonAsync<ResponseWrapper<GetAssetIdResponse>>();
71+
var result = await ReadAsJsonAsync<ResponseWrapper<GetAssetIdResponse>>(response);
5972
return result!;
6073
}
6174

@@ -66,7 +79,7 @@ public async Task<ResponseWrapper<GetVaultIdResponse>> GetVaultId(GetVaultIdMess
6679
var client = HttpClientWithReddioUA();
6780
var response = await client.GetAsync(endpoint);
6881
response.EnsureSuccessStatusCode();
69-
var result = await response.Content.ReadFromJsonAsync<ResponseWrapper<GetVaultIdResponse>>();
82+
var result = await ReadAsJsonAsync<ResponseWrapper<GetVaultIdResponse>>(response);
7083
return result!;
7184
}
7285

@@ -78,7 +91,7 @@ public async Task<ResponseWrapper<GetRecordResponse>> GetRecord(GetRecordMessage
7891
var response = await client.GetAsync(endpoint);
7992
var body = await response.Content.ReadAsStringAsync();
8093
response.EnsureSuccessStatusCode();
81-
var result = await response.Content.ReadFromJsonAsync<ResponseWrapper<GetRecordResponse>>();
94+
var result = await ReadAsJsonAsync<ResponseWrapper<GetRecordResponse>>(response);
8295
return result!;
8396
}
8497

reddio-csharp/reddio.api/V1/Rest/ResponseWrapper.cs

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

33
namespace Reddio.Api.V1.Rest
44
{
55
public class ResponseWrapper<T>
66
{
7-
[JsonPropertyName("status")] public string Status { get; set; }
8-
[JsonPropertyName("error")] public string Error { get; set; }
9-
[JsonPropertyName("data")] public T Data { get; set; }
7+
[JsonProperty("status")] public string Status { get; set; }
8+
[JsonProperty("error")] public string Error { get; set; }
9+
[JsonProperty("data")] public T Data { get; set; }
1010

1111
public ResponseWrapper()
1212
{

reddio-csharp/reddio.api/V1/Rest/Signature.cs

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

33
namespace Reddio.Api.V1.Rest
44
{
55
public class Signature
66
{
7-
[JsonPropertyName("r")] public string R { get; set; }
8-
[JsonPropertyName("s")] public string S { get; set; }
7+
[JsonProperty("r")] public string R { get; set; }
8+
[JsonProperty("s")] public string S { get; set; }
99

1010
public Signature(string r, string s)
1111
{

reddio-csharp/reddio.api/V1/Rest/TransferMessage.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
using System;
2-
using System.Numerics;
3-
using System.Text.Json.Serialization;
2+
using Newtonsoft.Json;
43

54
namespace Reddio.Api.V1.Rest
65
{
76
public class TransferMessage
87
{
9-
[JsonPropertyName("asset_id")] public string AssetId { get; set; }
10-
[JsonPropertyName("stark_key")] public string StarkKey { get; set; }
11-
[JsonPropertyName("amount")] public string Amount { get; set; }
12-
[JsonPropertyName("nonce")] public Int64 Nonce { get; set; }
13-
[JsonPropertyName("vault_id")] public string VaultId { get; set; }
14-
[JsonPropertyName("receiver")] public string Receiver { get; set; }
8+
[JsonProperty("asset_id")] public string AssetId { get; set; }
9+
[JsonProperty("stark_key")] public string StarkKey { get; set; }
10+
[JsonProperty("amount")] public string Amount { get; set; }
11+
[JsonProperty("nonce")] public Int64 Nonce { get; set; }
12+
[JsonProperty("vault_id")] public string VaultId { get; set; }
13+
[JsonProperty("receiver")] public string Receiver { get; set; }
1514

16-
[JsonPropertyName("receiver_vault_id")]
15+
[JsonProperty("receiver_vault_id")]
1716
public string ReceiverVaultId { get; set; }
1817

19-
[JsonPropertyName("expiration_timestamp")]
18+
[JsonProperty("expiration_timestamp")]
2019
public Int64 ExpirationTimestamp { get; set; }
2120

22-
[JsonPropertyName("signature")] public Signature Signature { get; set; }
21+
[JsonProperty("signature")] public Signature Signature { get; set; }
2322

2423
public TransferMessage()
2524
{

reddio-csharp/reddio.api/V1/Rest/TransferResponse.cs

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

44
namespace Reddio.Api.V1.Rest
55
{
@@ -14,6 +14,6 @@ public TransferResponse(long sequenceId)
1414
SequenceId = sequenceId;
1515
}
1616

17-
[JsonPropertyName("sequence_id")] public Int64 SequenceId { get; set; }
17+
[JsonProperty("sequence_id")] public Int64 SequenceId { get; set; }
1818
}
1919
}

reddio-csharp/reddio.api/reddio.api.csproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
5-
<ImplicitUsings>enable</ImplicitUsings>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<ImplicitUsings>disable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<LangVersion>9</LangVersion>
88
</PropertyGroup>
@@ -14,4 +14,8 @@
1414
</AssemblyAttribute>
1515
</ItemGroup>
1616

17+
<ItemGroup>
18+
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
19+
</ItemGroup>
20+
1721
</Project>

0 commit comments

Comments
 (0)