Skip to content

Commit 25fe4b9

Browse files
Merge pull request #32 from ipdata/claude/migrate-ipdata-references-TUE1b
Migrate from Newtonsoft.Json to System.Text.Json
2 parents 03b4480 + ce100c8 commit 25fe4b9

13 files changed

Lines changed: 90 additions & 98 deletions
Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,22 @@
1-
using System.Globalization;
2-
using Newtonsoft.Json;
3-
using Newtonsoft.Json.Converters;
1+
using System.Text.Json;
42

53
namespace IPData.Http.Serializer
64
{
75
internal class JsonSerializer : ISerializer
86
{
9-
private static readonly JsonSerializerSettings _settings = new JsonSerializerSettings
7+
private static readonly JsonSerializerOptions _options = new JsonSerializerOptions
108
{
11-
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
12-
DateParseHandling = DateParseHandling.None,
13-
Converters =
14-
{
15-
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
16-
}
9+
IgnoreNullValues = true
1710
};
1811

1912
public T Deserialize<T>(string json)
2013
{
21-
return JsonConvert.DeserializeObject<T>(json, _settings);
14+
return System.Text.Json.JsonSerializer.Deserialize<T>(json, _options);
2215
}
2316

2417
public string Serialize(object item)
2518
{
26-
return JsonConvert.SerializeObject(item, _settings);
19+
return System.Text.Json.JsonSerializer.Serialize(item, _options);
2720
}
2821
}
2922
}

src/IPData/IPData.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
</PropertyGroup>
2626

2727
<ItemGroup>
28-
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
28+
<PackageReference Include="System.Text.Json" Version="4.7.2" />
2929
</ItemGroup>
3030

3131
</Project>

src/IPData/IPData.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<repository type="git" url="https://github.com/ipdata/dotnet" />
1717
<dependencies>
1818
<group targetFramework=".NETStandard2.0">
19-
<dependency id="Newtonsoft.Json" version="12.0.2" exclude="Build,Analyzers" />
19+
<dependency id="System.Text.Json" version="4.7.2" exclude="Build,Analyzers" />
2020
</group>
2121
</dependencies>
2222
</metadata>

src/IPData/Models/ApiError.cs

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

33
namespace IPData.Models
44
{
@@ -13,7 +13,7 @@ public ApiError(string message)
1313
Message = message;
1414
}
1515

16-
[JsonProperty("message")]
16+
[JsonPropertyName("message")]
1717
public string Message { get; set; }
1818
}
1919
}

src/IPData/Models/AsnInfo.cs

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

33
namespace IPData.Models
44
{
55
public class AsnInfo
66
{
7-
[JsonProperty("asn", NullValueHandling = NullValueHandling.Ignore)]
7+
[JsonPropertyName("asn")]
88
public string Asn { get; set; }
99

10-
[JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)]
10+
[JsonPropertyName("name")]
1111
public string Name { get; set; }
1212

13-
[JsonProperty("domain", NullValueHandling = NullValueHandling.Ignore)]
13+
[JsonPropertyName("domain")]
1414
public string Domain { get; set; }
1515

16-
[JsonProperty("route", NullValueHandling = NullValueHandling.Ignore)]
16+
[JsonPropertyName("route")]
1717
public string Route { get; set; }
1818

19-
[JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)]
19+
[JsonPropertyName("type")]
2020
public string Type { get; set; }
2121
}
2222
}

src/IPData/Models/BlocklistInfo.cs

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

33
namespace IPData.Models
44
{
55
public class BlocklistInfo
66
{
7-
[JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)]
7+
[JsonPropertyName("name")]
88
public string Name { get; set; }
99

10-
[JsonProperty("site", NullValueHandling = NullValueHandling.Ignore)]
10+
[JsonPropertyName("site")]
1111
public string Site { get; set; }
1212

13-
[JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)]
13+
[JsonPropertyName("type")]
1414
public string Type { get; set; }
1515
}
1616
}

src/IPData/Models/CarrierInfo.cs

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

33
namespace IPData.Models
44
{
55
public class CarrierInfo
66
{
7-
[JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)]
7+
[JsonPropertyName("name")]
88
public string Name { get; set; }
99

10-
[JsonProperty("mcc", NullValueHandling = NullValueHandling.Ignore)]
10+
[JsonPropertyName("mcc")]
1111
public string Mcc { get; set; }
1212

13-
[JsonProperty("mnc", NullValueHandling = NullValueHandling.Ignore)]
13+
[JsonPropertyName("mnc")]
1414
public string Mnc { get; set; }
1515
}
16-
1716
}

src/IPData/Models/CompanyInfo.cs

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

33
namespace IPData.Models
44
{
55
public class CompanyInfo
66
{
7-
[JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)]
7+
[JsonPropertyName("name")]
88
public string Name { get; set; }
99

10-
[JsonProperty("domain", NullValueHandling = NullValueHandling.Ignore)]
10+
[JsonPropertyName("domain")]
1111
public string Domain { get; set; }
1212

13-
[JsonProperty("network", NullValueHandling = NullValueHandling.Ignore)]
13+
[JsonPropertyName("network")]
1414
public string Network { get; set; }
1515

16-
[JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)]
16+
[JsonPropertyName("type")]
1717
public string Type { get; set; }
1818
}
1919
}

src/IPData/Models/Currency.cs

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

33
namespace IPData.Models
44
{
55
public class Currency
66
{
7-
[JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)]
7+
[JsonPropertyName("name")]
88
public string Name { get; set; }
99

10-
[JsonProperty("code", NullValueHandling = NullValueHandling.Ignore)]
10+
[JsonPropertyName("code")]
1111
public string Code { get; set; }
1212

13-
[JsonProperty("symbol", NullValueHandling = NullValueHandling.Ignore)]
13+
[JsonPropertyName("symbol")]
1414
public string Symbol { get; set; }
1515

16-
[JsonProperty("native", NullValueHandling = NullValueHandling.Ignore)]
16+
[JsonPropertyName("native")]
1717
public string Native { get; set; }
1818

19-
[JsonProperty("plural", NullValueHandling = NullValueHandling.Ignore)]
19+
[JsonPropertyName("plural")]
2020
public string Plural { get; set; }
2121
}
2222
}
Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,104 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Linq.Expressions;
5+
using System.Text.Json.Serialization;
56
using IPData.Helpers.Extensions;
6-
using Newtonsoft.Json;
77

88
namespace IPData.Models
99
{
1010
public class IPLookupResult
1111
{
12-
[JsonProperty("ip", NullValueHandling = NullValueHandling.Ignore)]
12+
[JsonPropertyName("ip")]
1313
public string Ip { get; set; }
1414

15-
[JsonProperty("is_eu", NullValueHandling = NullValueHandling.Ignore)]
15+
[JsonPropertyName("is_eu")]
1616
public bool? IsEu { get; set; }
1717

18-
[JsonProperty("city", NullValueHandling = NullValueHandling.Ignore)]
18+
[JsonPropertyName("city")]
1919
public string City { get; set; }
2020

21-
[JsonProperty("region", NullValueHandling = NullValueHandling.Ignore)]
21+
[JsonPropertyName("region")]
2222
public string Region { get; set; }
2323

24-
[JsonProperty("region_code", NullValueHandling = NullValueHandling.Ignore)]
24+
[JsonPropertyName("region_code")]
2525
public string RegionCode { get; set; }
2626

27-
[JsonProperty("country_name", NullValueHandling = NullValueHandling.Ignore)]
27+
[JsonPropertyName("country_name")]
2828
public string CountryName { get; set; }
2929

30-
[JsonProperty("country_code", NullValueHandling = NullValueHandling.Ignore)]
30+
[JsonPropertyName("country_code")]
3131
public string CountryCode { get; set; }
3232

33-
[JsonProperty("continent_name", NullValueHandling = NullValueHandling.Ignore)]
33+
[JsonPropertyName("continent_name")]
3434
public string ContinentName { get; set; }
3535

36-
[JsonProperty("continent_code", NullValueHandling = NullValueHandling.Ignore)]
36+
[JsonPropertyName("continent_code")]
3737
public string ContinentCode { get; set; }
3838

39-
[JsonProperty("latitude", NullValueHandling = NullValueHandling.Ignore)]
39+
[JsonPropertyName("latitude")]
4040
public double? Latitude { get; set; }
4141

42-
[JsonProperty("longitude", NullValueHandling = NullValueHandling.Ignore)]
42+
[JsonPropertyName("longitude")]
4343
public double? Longitude { get; set; }
4444

45-
[JsonProperty("asn", NullValueHandling = NullValueHandling.Ignore)]
45+
[JsonPropertyName("asn")]
4646
public AsnInfo Asn { get; set; }
4747

48-
[JsonProperty("organisation", NullValueHandling = NullValueHandling.Ignore)]
48+
[JsonPropertyName("organisation")]
4949
public string Organisation { get; set; }
5050

51-
[JsonProperty("postal", NullValueHandling = NullValueHandling.Ignore)]
51+
[JsonPropertyName("postal")]
5252
public string Postal { get; set; }
5353

54-
[JsonProperty("calling_code", NullValueHandling = NullValueHandling.Ignore)]
54+
[JsonPropertyName("calling_code")]
5555
public string CallingCode { get; set; }
5656

57-
[JsonProperty("flag", NullValueHandling = NullValueHandling.Ignore)]
57+
[JsonPropertyName("flag")]
5858
public Uri Flag { get; set; }
5959

60-
[JsonProperty("emoji_flag", NullValueHandling = NullValueHandling.Ignore)]
60+
[JsonPropertyName("emoji_flag")]
6161
public string EmojiFlag { get; set; }
6262

63-
[JsonProperty("emoji_unicode", NullValueHandling = NullValueHandling.Ignore)]
63+
[JsonPropertyName("emoji_unicode")]
6464
public string EmojiUnicode { get; set; }
6565

66-
[JsonProperty("languages")]
66+
[JsonPropertyName("languages")]
6767
public List<Language> Languages { get; private set; } = new List<Language>();
6868

69-
[JsonProperty("currency")]
69+
[JsonPropertyName("currency")]
7070
public Currency Currency { get; set; }
7171

72-
[JsonProperty("time_zone")]
72+
[JsonPropertyName("time_zone")]
7373
public TimeZone TimeZone { get; set; }
7474

75-
[JsonProperty("threat")]
75+
[JsonPropertyName("threat")]
7676
public Threat Threat { get; set; }
7777

78-
[JsonProperty("region_type", NullValueHandling = NullValueHandling.Ignore)]
78+
[JsonPropertyName("region_type")]
7979
public string RegionType { get; set; }
8080

81-
[JsonProperty("carrier", NullValueHandling = NullValueHandling.Ignore)]
81+
[JsonPropertyName("carrier")]
8282
public CarrierInfo Carrier { get; set; }
8383

84-
[JsonProperty("company", NullValueHandling = NullValueHandling.Ignore)]
84+
[JsonPropertyName("company")]
8585
public CompanyInfo Company { get; set; }
8686

87-
[JsonProperty("status", NullValueHandling = NullValueHandling.Ignore)]
87+
[JsonPropertyName("status")]
8888
public int? Status { get; set; }
8989

90-
[JsonProperty("count")]
90+
[JsonPropertyName("count")]
9191
public int Count { get; set; }
9292

9393
internal static string FieldName(Expression<Func<IPLookupResult, object>> expression)
9494
{
9595
var propName = expression.PropertyName();
9696
var attribute = typeof(IPLookupResult)
9797
.GetProperty(propName)
98-
?.GetCustomAttributes(typeof(JsonPropertyAttribute), false)
99-
.Single() as JsonPropertyAttribute;
98+
?.GetCustomAttributes(typeof(JsonPropertyNameAttribute), false)
99+
.Single() as JsonPropertyNameAttribute;
100100

101-
return attribute?.PropertyName ?? string.Empty;
101+
return attribute?.Name ?? string.Empty;
102102
}
103103
}
104-
}
104+
}

0 commit comments

Comments
 (0)