Skip to content

Commit 2f77ac5

Browse files
authored
replace ntjson with stjson (#315)
Signed-off-by: catcherwong <[email protected]>
1 parent 85719cc commit 2f77ac5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+177
-168
lines changed

src/Nacos/Nacos.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
</ItemGroup>
4848

4949
<ItemGroup>
50-
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
50+
<PackageReference Include="System.Text.Json" Version="8.0.4" />
5151
<PackageReference Include="Google.Protobuf" Version="3.27.2" />
5252
<PackageReference Include="Grpc.Net.Client" Version="2.65.0" />
5353
<!--<PackageReference Include="Grpc.Net.Client" Version="2.33.1" />-->

src/Nacos/OpenApi/DefaultNacosOpenApi.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ public async Task<List<NacosNamespace>> GetNamespacesAsync()
9797
if (resp.IsSuccessStatusCode)
9898
{
9999
var res = await resp.Content.ReadAsStringAsync().ConfigureAwait(false);
100-
var jobj = Newtonsoft.Json.Linq.JObject.Parse(res);
100+
var jobj = System.Text.Json.Nodes.JsonNode.Parse(res).AsObject();
101101

102-
if (jobj.TryGetValue("data", System.StringComparison.OrdinalIgnoreCase, out var val))
102+
if (jobj.TryGetPropertyValue("data", out var val))
103103
{
104104
return val.ToString().ToObj<List<NacosNamespace>>();
105105
}

src/Nacos/OpenApi/Models/NacosMetrics.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,49 @@
22
{
33
public class NacosMetrics
44
{
5-
[Newtonsoft.Json.JsonProperty("status")]
5+
[System.Text.Json.Serialization.JsonPropertyName("status")]
66
public string Status { get; set; }
77

8-
[Newtonsoft.Json.JsonProperty("serviceCount")]
8+
[System.Text.Json.Serialization.JsonPropertyName("serviceCount")]
99
public int ServiceCount { get; set; }
1010

11-
[Newtonsoft.Json.JsonProperty("instanceCount")]
11+
[System.Text.Json.Serialization.JsonPropertyName("instanceCount")]
1212
public int InstanceCount { get; set; }
1313

14-
[Newtonsoft.Json.JsonProperty("subscribeCount")]
14+
[System.Text.Json.Serialization.JsonPropertyName("subscribeCount")]
1515
public int SubscribeCount { get; set; }
1616

17-
[Newtonsoft.Json.JsonProperty("raftNotifyTaskCount")]
17+
[System.Text.Json.Serialization.JsonPropertyName("raftNotifyTaskCount")]
1818
public int RaftNotifyTaskCount { get; set; }
1919

20-
[Newtonsoft.Json.JsonProperty("responsibleServiceCount")]
20+
[System.Text.Json.Serialization.JsonPropertyName("responsibleServiceCount")]
2121
public int ResponsibleServiceCount { get; set; }
2222

23-
[Newtonsoft.Json.JsonProperty("responsibleInstanceCount")]
23+
[System.Text.Json.Serialization.JsonPropertyName("responsibleInstanceCount")]
2424
public int ResponsibleInstanceCount { get; set; }
2525

26-
[Newtonsoft.Json.JsonProperty("clientCount")]
26+
[System.Text.Json.Serialization.JsonPropertyName("clientCount")]
2727
public int ClientCount { get; set; }
2828

29-
[Newtonsoft.Json.JsonProperty("connectionBasedClientCount")]
29+
[System.Text.Json.Serialization.JsonPropertyName("connectionBasedClientCount")]
3030
public int ConnectionBasedClientCount { get; set; }
3131

32-
[Newtonsoft.Json.JsonProperty("ephemeralIpPortClientCount")]
32+
[System.Text.Json.Serialization.JsonPropertyName("ephemeralIpPortClientCount")]
3333
public int EphemeralIpPortClientCount { get; set; }
3434

35-
[Newtonsoft.Json.JsonProperty("persistentIpPortClientCount")]
35+
[System.Text.Json.Serialization.JsonPropertyName("persistentIpPortClientCount")]
3636
public int PersistentIpPortClientCount { get; set; }
3737

38-
[Newtonsoft.Json.JsonProperty("responsibleClientCount")]
38+
[System.Text.Json.Serialization.JsonPropertyName("responsibleClientCount")]
3939
public int ResponsibleClientCount { get; set; }
4040

41-
[Newtonsoft.Json.JsonProperty("cpu")]
41+
[System.Text.Json.Serialization.JsonPropertyName("cpu")]
4242
public float Cpu { get; set; }
4343

44-
[Newtonsoft.Json.JsonProperty("load")]
44+
[System.Text.Json.Serialization.JsonPropertyName("load")]
4545
public float Load { get; set; }
4646

47-
[Newtonsoft.Json.JsonProperty("mem")]
47+
[System.Text.Json.Serialization.JsonPropertyName("mem")]
4848
public float Mem { get; set; }
4949
}
5050
}

src/Nacos/OpenApi/Models/NacosNamespace.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
{
33
public class NacosNamespace
44
{
5-
[Newtonsoft.Json.JsonProperty("namespace")]
5+
[System.Text.Json.Serialization.JsonPropertyName("namespace")]
66
public string Namespace { get; set; }
77

8-
[Newtonsoft.Json.JsonProperty("namespaceShowName")]
8+
[System.Text.Json.Serialization.JsonPropertyName("namespaceShowName")]
99
public string NamespaceShowName { get; set; }
1010

11-
[Newtonsoft.Json.JsonProperty("namespaceDesc")]
11+
[System.Text.Json.Serialization.JsonPropertyName("namespaceDesc")]
1212
public string NamespaceDesc { get; set; }
1313

14-
[Newtonsoft.Json.JsonProperty("quota")]
14+
[System.Text.Json.Serialization.JsonPropertyName("quota")]
1515
public int Quota { get; set; }
1616

17-
[Newtonsoft.Json.JsonProperty("configCount")]
17+
[System.Text.Json.Serialization.JsonPropertyName("configCount")]
1818
public int ConfigCount { get; set; }
1919

20-
[Newtonsoft.Json.JsonProperty("type")]
20+
[System.Text.Json.Serialization.JsonPropertyName("type")]
2121
public int Type { get; set; }
2222
}
2323
}

src/Nacos/V2/Naming/Beat/BeatInfo.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,31 @@
55

66
public class BeatInfo
77
{
8-
[Newtonsoft.Json.JsonProperty("port")]
8+
[System.Text.Json.Serialization.JsonPropertyName("port")]
99
public int Port { get; set; }
1010

11-
[Newtonsoft.Json.JsonProperty("ip")]
11+
[System.Text.Json.Serialization.JsonPropertyName("ip")]
1212
public string Ip { get; set; }
1313

14-
[Newtonsoft.Json.JsonProperty("weight")]
14+
[System.Text.Json.Serialization.JsonPropertyName("weight")]
1515
public double? Weight { get; set; }
1616

17-
[Newtonsoft.Json.JsonProperty("serviceName")]
17+
[System.Text.Json.Serialization.JsonPropertyName("serviceName")]
1818
public string ServiceName { get; set; }
1919

20-
[Newtonsoft.Json.JsonProperty("cluster")]
20+
[System.Text.Json.Serialization.JsonPropertyName("cluster")]
2121
public string Cluster { get; set; }
2222

23-
[Newtonsoft.Json.JsonProperty("metadata")]
23+
[System.Text.Json.Serialization.JsonPropertyName("metadata")]
2424
public Dictionary<string, string> Metadata { get; set; } = new Dictionary<string, string>();
2525

26-
[Newtonsoft.Json.JsonProperty("scheduled")]
26+
[System.Text.Json.Serialization.JsonPropertyName("scheduled")]
2727
public bool Scheduled { get; set; }
2828

29-
[Newtonsoft.Json.JsonProperty("period")]
29+
[System.Text.Json.Serialization.JsonPropertyName("period")]
3030
public long Period { get; set; }
3131

32-
[Newtonsoft.Json.JsonProperty("stopped")]
32+
[System.Text.Json.Serialization.JsonPropertyName("stopped")]
3333
public bool Stopped { get; set; }
3434

3535
public override string ToString()

src/Nacos/V2/Naming/Beat/BeatReactor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,22 @@ private async Task BeatTask(BeatInfo beatInfo)
6565

6666
try
6767
{
68-
Newtonsoft.Json.Linq.JObject result = await _serverProxy.SendBeat(beatInfo, false).ConfigureAwait(false);
68+
System.Text.Json.Nodes.JsonObject result = await _serverProxy.SendBeat(beatInfo, false).ConfigureAwait(false);
6969
_logger?.LogDebug("[CLIENT-BEAT] sendbeat result = {0}", result.ToString());
70-
long interval = result.GetValue(CLIENT_BEAT_INTERVAL_FIELD).ToObject<long>();
70+
var interval = result[CLIENT_BEAT_INTERVAL_FIELD].GetValue<long>();
7171

7272
bool lightBeatEnabled = false;
7373

7474
if (result.ContainsKey(CommonParams.LIGHT_BEAT_ENABLED))
7575
{
76-
lightBeatEnabled = result.GetValue(CommonParams.LIGHT_BEAT_ENABLED).ToObject<bool>();
76+
lightBeatEnabled = result[CommonParams.LIGHT_BEAT_ENABLED].GetValue<bool>();
7777
}
7878

7979
if (interval > 0) nextTime = interval;
8080

8181
int code = OK;
8282

83-
if (result.ContainsKey(CommonParams.CODE)) code = result.GetValue(CommonParams.CODE).ToObject<int>();
83+
if (result.ContainsKey(CommonParams.CODE)) code = result[CommonParams.CODE].GetValue<int>();
8484

8585
if (code == RESOURCE_NOT_FOUND)
8686
{

src/Nacos/V2/Naming/Dtos/Instance.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,61 +11,61 @@ public class Instance
1111
/// <summary>
1212
/// unique id of this instance.
1313
/// </summary>
14-
[Newtonsoft.Json.JsonProperty("instanceId")]
14+
[System.Text.Json.Serialization.JsonPropertyName("instanceId")]
1515
public string InstanceId { get; set; }
1616

1717
/// <summary>
1818
/// instance ip.
1919
/// </summary>
20-
[Newtonsoft.Json.JsonProperty("ip")]
20+
[System.Text.Json.Serialization.JsonPropertyName("ip")]
2121
public string Ip { get; set; }
2222

2323
/// <summary>
2424
/// instance port.
2525
/// </summary>
26-
[Newtonsoft.Json.JsonProperty("port")]
26+
[System.Text.Json.Serialization.JsonPropertyName("port")]
2727
public int Port { get; set; }
2828

2929
/// <summary>
3030
/// instance weight.
3131
/// </summary>
32-
[Newtonsoft.Json.JsonProperty("weight")]
32+
[System.Text.Json.Serialization.JsonPropertyName("weight")]
3333
public double Weight { get; set; } = 1.0D;
3434

3535
/// <summary>
3636
/// instance health status.
3737
/// </summary>
38-
[Newtonsoft.Json.JsonProperty("healthy")]
38+
[System.Text.Json.Serialization.JsonPropertyName("healthy")]
3939
public bool Healthy { get; set; } = true;
4040

4141
/// <summary>
4242
/// If instance is enabled to accept request.
4343
/// </summary>
44-
[Newtonsoft.Json.JsonProperty("enabled")]
44+
[System.Text.Json.Serialization.JsonPropertyName("enabled")]
4545
public bool Enabled { get; set; } = true;
4646

4747
/// <summary>
4848
/// If instance is ephemeral.
4949
/// </summary>
50-
[Newtonsoft.Json.JsonProperty("ephemeral")]
50+
[System.Text.Json.Serialization.JsonPropertyName("ephemeral")]
5151
public bool Ephemeral { get; set; } = true;
5252

5353
/// <summary>
5454
/// cluster information of instance.
5555
/// </summary>
56-
[Newtonsoft.Json.JsonProperty("clusterName")]
56+
[System.Text.Json.Serialization.JsonPropertyName("clusterName")]
5757
public string ClusterName { get; set; }
5858

5959
/// <summary>
6060
/// Service information of instance.
6161
/// </summary>
62-
[Newtonsoft.Json.JsonProperty("serviceName")]
62+
[System.Text.Json.Serialization.JsonPropertyName("serviceName")]
6363
public string ServiceName { get; set; }
6464

6565
/// <summary>
6666
/// user extended attributes.
6767
/// </summary>
68-
[Newtonsoft.Json.JsonProperty("metadata")]
68+
[System.Text.Json.Serialization.JsonPropertyName("metadata")]
6969
public Dictionary<string, string> Metadata { get; set; } = new Dictionary<string, string>();
7070

7171
public void AddMetadata(string key, string value)

src/Nacos/V2/Naming/Dtos/ServiceInfo.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@
88

99
public class ServiceInfo
1010
{
11-
[Newtonsoft.Json.JsonProperty("name")]
11+
[System.Text.Json.Serialization.JsonPropertyName("name")]
1212
public string Name { get; set; }
1313

14-
[Newtonsoft.Json.JsonProperty("groupName")]
14+
[System.Text.Json.Serialization.JsonPropertyName("groupName")]
1515
public string GroupName { get; set; }
1616

17-
[Newtonsoft.Json.JsonProperty("cacheMillis")]
17+
[System.Text.Json.Serialization.JsonPropertyName("cacheMillis")]
1818
public long CacheMillis { get; set; } = 1000L;
1919

20-
[Newtonsoft.Json.JsonProperty("lastRefTime")]
20+
[System.Text.Json.Serialization.JsonPropertyName("lastRefTime")]
2121
public long LastRefTime { get; set; } = 0L;
2222

23-
[Newtonsoft.Json.JsonProperty("checksum")]
23+
[System.Text.Json.Serialization.JsonPropertyName("checksum")]
2424
public string Checksum { get; set; } = "";
2525

26-
[Newtonsoft.Json.JsonProperty("hosts")]
26+
[System.Text.Json.Serialization.JsonPropertyName("hosts")]
2727
public List<Instance> Hosts { get; set; } = new List<Instance>();
2828

29-
[Newtonsoft.Json.JsonProperty("metallIPsadata")]
29+
[System.Text.Json.Serialization.JsonPropertyName("metallIPsadata")]
3030
public bool AllIPs { get; set; } = false;
3131

32-
[Newtonsoft.Json.JsonProperty("clusters")]
32+
[System.Text.Json.Serialization.JsonPropertyName("clusters")]
3333
public string Clusters { get; set; }
3434

3535
public ServiceInfo()
@@ -76,7 +76,7 @@ public static string GetKey(string name, string clusters)
7676
=> !string.IsNullOrEmpty(clusters) ? name + Constants.SERVICE_INFO_SPLITER + clusters : name;
7777

7878

79-
[Newtonsoft.Json.JsonIgnore]
79+
[System.Text.Json.Serialization.JsonIgnore]
8080
public string JsonFromServer { get; set; }
8181

8282
public string GetKeyEncoded() => GetKey(System.Net.WebUtility.UrlEncode(GetGroupedServiceName()), Clusters);

src/Nacos/V2/Naming/Event/InstancesChangeEvent.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55

66
public class InstancesChangeEvent : IEvent
77
{
8-
[Newtonsoft.Json.JsonProperty("serviceName")]
8+
[System.Text.Json.Serialization.JsonPropertyName("serviceName")]
99
public string ServiceName { get; set; }
1010

11-
[Newtonsoft.Json.JsonProperty("groupName")]
11+
[System.Text.Json.Serialization.JsonPropertyName("groupName")]
1212
public string GroupName { get; set; }
1313

14-
[Newtonsoft.Json.JsonProperty("clusters")]
14+
[System.Text.Json.Serialization.JsonPropertyName("clusters")]
1515
public string Clusters { get; set; }
1616

17-
[Newtonsoft.Json.JsonProperty("hosts")]
17+
[System.Text.Json.Serialization.JsonPropertyName("hosts")]
1818
public List<Instance> Hosts { get; set; }
1919

2020
public InstancesChangeEvent(string serviceName, string groupName, string clusters, List<Instance> hosts)

src/Nacos/V2/Naming/Remote/Http/NamingHttpClientProxy.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public NamingHttpClientProxy(
7272
this.serviceInfoHolder = serviceInfoHolder;
7373
}
7474

75-
internal async Task<Newtonsoft.Json.Linq.JObject> SendBeat(BeatInfo beatInfo, bool lightBeatEnabled)
75+
internal async Task<System.Text.Json.Nodes.JsonObject> SendBeat(BeatInfo beatInfo, bool lightBeatEnabled)
7676
{
7777
var parameters = new Dictionary<string, string>()
7878
{
@@ -88,7 +88,7 @@ public NamingHttpClientProxy(
8888
if (!lightBeatEnabled) body["beat"] = beatInfo.ToJsonString();
8989

9090
var result = await ReqApi(UtilAndComs.NacosUrlBase + "/instance/beat", parameters, body, HttpMethod.Put).ConfigureAwait(false);
91-
return Newtonsoft.Json.Linq.JObject.Parse(result);
91+
return System.Text.Json.Nodes.JsonNode.Parse(result).AsObject();
9292
}
9393

9494
private void SetServerPort(int serverPort)
@@ -177,9 +177,9 @@ public async Task<ListView<string>> GetServiceList(int pageNo, int pageSize, str
177177

178178
var result = await ReqApi(UtilAndComs.NacosUrlBase + "/service/list", paramters, HttpMethod.Get).ConfigureAwait(false);
179179

180-
var json = Newtonsoft.Json.Linq.JObject.Parse(result);
181-
var count = json.GetValue("count")?.ToObject<int>() ?? 0;
182-
var data = json.GetValue("doms")?.ToObject<List<string>>() ?? new List<string>();
180+
var json = System.Text.Json.Nodes.JsonNode.Parse(result).AsObject();
181+
var count = json["count"]?.GetValue<int>() ?? 0;
182+
var data = json["doms"]?.GetValue<List<string>>() ?? new List<string>();
183183

184184
ListView<string> listView = new ListView<string>(count, data);
185185
return listView;
@@ -411,9 +411,9 @@ public bool ServerHealthy()
411411
string result = ReqApi(UtilAndComs.NacosUrlBase + "/operator/metrics", new Dictionary<string, string>(),
412412
HttpMethod.Get).ConfigureAwait(false).GetAwaiter().GetResult();
413413

414-
var json = Newtonsoft.Json.Linq.JObject.Parse(result);
414+
var json = System.Text.Json.Nodes.JsonNode.Parse(result).AsObject();
415415

416-
string serverStatus = json.GetValue("status")?.ToString();
416+
string serverStatus = json["status"]?.GetValue<string>();
417417
return "UP".Equals(serverStatus);
418418
}
419419
catch

src/Nacos/V2/Remote/CommonRequest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
public abstract class CommonRequest
66
{
7-
[Newtonsoft.Json.JsonProperty("headers")]
7+
[System.Text.Json.Serialization.JsonPropertyName("headers")]
88
public System.Collections.Generic.Dictionary<string, string> Headers { get; set; } = new System.Collections.Generic.Dictionary<string, string>();
99

10-
[Newtonsoft.Json.JsonProperty("requestId")]
10+
[System.Text.Json.Serialization.JsonPropertyName("requestId")]
1111
public string RequestId { get; set; }
1212

1313
public void PutHeader(string key, string value)

0 commit comments

Comments
 (0)