Skip to content

Commit

Permalink
replace ntjson with stjson (#315)
Browse files Browse the repository at this point in the history
Signed-off-by: catcherwong <[email protected]>
  • Loading branch information
catcherwong authored Sep 17, 2024
1 parent 85719cc commit 2f77ac5
Show file tree
Hide file tree
Showing 45 changed files with 177 additions and 168 deletions.
2 changes: 1 addition & 1 deletion src/Nacos/Nacos.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
<PackageReference Include="Google.Protobuf" Version="3.27.2" />
<PackageReference Include="Grpc.Net.Client" Version="2.65.0" />
<!--<PackageReference Include="Grpc.Net.Client" Version="2.33.1" />-->
Expand Down
4 changes: 2 additions & 2 deletions src/Nacos/OpenApi/DefaultNacosOpenApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ public async Task<List<NacosNamespace>> GetNamespacesAsync()
if (resp.IsSuccessStatusCode)
{
var res = await resp.Content.ReadAsStringAsync().ConfigureAwait(false);
var jobj = Newtonsoft.Json.Linq.JObject.Parse(res);
var jobj = System.Text.Json.Nodes.JsonNode.Parse(res).AsObject();

if (jobj.TryGetValue("data", System.StringComparison.OrdinalIgnoreCase, out var val))
if (jobj.TryGetPropertyValue("data", out var val))
{
return val.ToString().ToObj<List<NacosNamespace>>();
}
Expand Down
30 changes: 15 additions & 15 deletions src/Nacos/OpenApi/Models/NacosMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,49 @@
{
public class NacosMetrics
{
[Newtonsoft.Json.JsonProperty("status")]
[System.Text.Json.Serialization.JsonPropertyName("status")]
public string Status { get; set; }

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

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

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

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

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

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

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

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

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

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

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

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

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

[Newtonsoft.Json.JsonProperty("mem")]
[System.Text.Json.Serialization.JsonPropertyName("mem")]
public float Mem { get; set; }
}
}
12 changes: 6 additions & 6 deletions src/Nacos/OpenApi/Models/NacosNamespace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
{
public class NacosNamespace
{
[Newtonsoft.Json.JsonProperty("namespace")]
[System.Text.Json.Serialization.JsonPropertyName("namespace")]
public string Namespace { get; set; }

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

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

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

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

[Newtonsoft.Json.JsonProperty("type")]
[System.Text.Json.Serialization.JsonPropertyName("type")]
public int Type { get; set; }
}
}
18 changes: 9 additions & 9 deletions src/Nacos/V2/Naming/Beat/BeatInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@

public class BeatInfo
{
[Newtonsoft.Json.JsonProperty("port")]
[System.Text.Json.Serialization.JsonPropertyName("port")]
public int Port { get; set; }

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

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

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

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

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

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

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

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

public override string ToString()
Expand Down
8 changes: 4 additions & 4 deletions src/Nacos/V2/Naming/Beat/BeatReactor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,22 @@ private async Task BeatTask(BeatInfo beatInfo)

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

bool lightBeatEnabled = false;

if (result.ContainsKey(CommonParams.LIGHT_BEAT_ENABLED))
{
lightBeatEnabled = result.GetValue(CommonParams.LIGHT_BEAT_ENABLED).ToObject<bool>();
lightBeatEnabled = result[CommonParams.LIGHT_BEAT_ENABLED].GetValue<bool>();
}

if (interval > 0) nextTime = interval;

int code = OK;

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

if (code == RESOURCE_NOT_FOUND)
{
Expand Down
20 changes: 10 additions & 10 deletions src/Nacos/V2/Naming/Dtos/Instance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,61 +11,61 @@ public class Instance
/// <summary>
/// unique id of this instance.
/// </summary>
[Newtonsoft.Json.JsonProperty("instanceId")]
[System.Text.Json.Serialization.JsonPropertyName("instanceId")]
public string InstanceId { get; set; }

/// <summary>
/// instance ip.
/// </summary>
[Newtonsoft.Json.JsonProperty("ip")]
[System.Text.Json.Serialization.JsonPropertyName("ip")]
public string Ip { get; set; }

/// <summary>
/// instance port.
/// </summary>
[Newtonsoft.Json.JsonProperty("port")]
[System.Text.Json.Serialization.JsonPropertyName("port")]
public int Port { get; set; }

/// <summary>
/// instance weight.
/// </summary>
[Newtonsoft.Json.JsonProperty("weight")]
[System.Text.Json.Serialization.JsonPropertyName("weight")]
public double Weight { get; set; } = 1.0D;

/// <summary>
/// instance health status.
/// </summary>
[Newtonsoft.Json.JsonProperty("healthy")]
[System.Text.Json.Serialization.JsonPropertyName("healthy")]
public bool Healthy { get; set; } = true;

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

/// <summary>
/// If instance is ephemeral.
/// </summary>
[Newtonsoft.Json.JsonProperty("ephemeral")]
[System.Text.Json.Serialization.JsonPropertyName("ephemeral")]
public bool Ephemeral { get; set; } = true;

/// <summary>
/// cluster information of instance.
/// </summary>
[Newtonsoft.Json.JsonProperty("clusterName")]
[System.Text.Json.Serialization.JsonPropertyName("clusterName")]
public string ClusterName { get; set; }

/// <summary>
/// Service information of instance.
/// </summary>
[Newtonsoft.Json.JsonProperty("serviceName")]
[System.Text.Json.Serialization.JsonPropertyName("serviceName")]
public string ServiceName { get; set; }

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

public void AddMetadata(string key, string value)
Expand Down
18 changes: 9 additions & 9 deletions src/Nacos/V2/Naming/Dtos/ServiceInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@

public class ServiceInfo
{
[Newtonsoft.Json.JsonProperty("name")]
[System.Text.Json.Serialization.JsonPropertyName("name")]
public string Name { get; set; }

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

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

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

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

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

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

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

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


[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public string JsonFromServer { get; set; }

public string GetKeyEncoded() => GetKey(System.Net.WebUtility.UrlEncode(GetGroupedServiceName()), Clusters);
Expand Down
8 changes: 4 additions & 4 deletions src/Nacos/V2/Naming/Event/InstancesChangeEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

public class InstancesChangeEvent : IEvent
{
[Newtonsoft.Json.JsonProperty("serviceName")]
[System.Text.Json.Serialization.JsonPropertyName("serviceName")]
public string ServiceName { get; set; }

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

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

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

public InstancesChangeEvent(string serviceName, string groupName, string clusters, List<Instance> hosts)
Expand Down
14 changes: 7 additions & 7 deletions src/Nacos/V2/Naming/Remote/Http/NamingHttpClientProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public NamingHttpClientProxy(
this.serviceInfoHolder = serviceInfoHolder;
}

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

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

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

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

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

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

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

string serverStatus = json.GetValue("status")?.ToString();
string serverStatus = json["status"]?.GetValue<string>();
return "UP".Equals(serverStatus);
}
catch
Expand Down
4 changes: 2 additions & 2 deletions src/Nacos/V2/Remote/CommonRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

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

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

public void PutHeader(string key, string value)
Expand Down
Loading

0 comments on commit 2f77ac5

Please sign in to comment.