Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions src/IPData/Http/Serializer/JsonSerializer.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Text.Json;

namespace IPData.Http.Serializer
{
internal class JsonSerializer : ISerializer
{
private static readonly JsonSerializerSettings _settings = new JsonSerializerSettings
private static readonly JsonSerializerOptions _options = new JsonSerializerOptions
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
DateParseHandling = DateParseHandling.None,
Converters =
{
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
}
IgnoreNullValues = true
};

public T Deserialize<T>(string json)
{
return JsonConvert.DeserializeObject<T>(json, _settings);
return System.Text.Json.JsonSerializer.Deserialize<T>(json, _options);
}

public string Serialize(object item)
{
return JsonConvert.SerializeObject(item, _settings);
return System.Text.Json.JsonSerializer.Serialize(item, _options);
}
}
}
2 changes: 1 addition & 1 deletion src/IPData/IPData.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="System.Text.Json" Version="4.7.2" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/IPData/IPData.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<repository type="git" url="https://github.com/ipdata/dotnet" />
<dependencies>
<group targetFramework=".NETStandard2.0">
<dependency id="Newtonsoft.Json" version="12.0.2" exclude="Build,Analyzers" />
<dependency id="System.Text.Json" version="4.7.2" exclude="Build,Analyzers" />
</group>
</dependencies>
</metadata>
Expand Down
4 changes: 2 additions & 2 deletions src/IPData/Models/ApiError.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace IPData.Models
{
Expand All @@ -13,7 +13,7 @@ public ApiError(string message)
Message = message;
}

[JsonProperty("message")]
[JsonPropertyName("message")]
public string Message { get; set; }
}
}
12 changes: 6 additions & 6 deletions src/IPData/Models/AsnInfo.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace IPData.Models
{
public class AsnInfo
{
[JsonProperty("asn", NullValueHandling = NullValueHandling.Ignore)]
[JsonPropertyName("asn")]
public string Asn { get; set; }

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

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

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

[JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)]
[JsonPropertyName("type")]
public string Type { get; set; }
}
}
8 changes: 4 additions & 4 deletions src/IPData/Models/BlocklistInfo.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace IPData.Models
{
public class BlocklistInfo
{
[JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)]
[JsonPropertyName("name")]
public string Name { get; set; }

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

[JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)]
[JsonPropertyName("type")]
public string Type { get; set; }
}
}
9 changes: 4 additions & 5 deletions src/IPData/Models/CarrierInfo.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace IPData.Models
{
public class CarrierInfo
{
[JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)]
[JsonPropertyName("name")]
public string Name { get; set; }

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

[JsonProperty("mnc", NullValueHandling = NullValueHandling.Ignore)]
[JsonPropertyName("mnc")]
public string Mnc { get; set; }
}

}
10 changes: 5 additions & 5 deletions src/IPData/Models/CompanyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace IPData.Models
{
public class CompanyInfo
{
[JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)]
[JsonPropertyName("name")]
public string Name { get; set; }

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

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

[JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)]
[JsonPropertyName("type")]
public string Type { get; set; }
}
}
12 changes: 6 additions & 6 deletions src/IPData/Models/Currency.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace IPData.Models
{
public class Currency
{
[JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)]
[JsonPropertyName("name")]
public string Name { get; set; }

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

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

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

[JsonProperty("plural", NullValueHandling = NullValueHandling.Ignore)]
[JsonPropertyName("plural")]
public string Plural { get; set; }
}
}
66 changes: 33 additions & 33 deletions src/IPData/Models/IPLookupResult.cs
Original file line number Diff line number Diff line change
@@ -1,104 +1,104 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text.Json.Serialization;
using IPData.Helpers.Extensions;
using Newtonsoft.Json;

namespace IPData.Models
{
public class IPLookupResult
{
[JsonProperty("ip", NullValueHandling = NullValueHandling.Ignore)]
[JsonPropertyName("ip")]
public string Ip { get; set; }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[JsonProperty("currency")]
[JsonPropertyName("currency")]
public Currency Currency { get; set; }

[JsonProperty("time_zone")]
[JsonPropertyName("time_zone")]
public TimeZone TimeZone { get; set; }

[JsonProperty("threat")]
[JsonPropertyName("threat")]
public Threat Threat { get; set; }

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

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

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

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

[JsonProperty("count")]
[JsonPropertyName("count")]
public int Count { get; set; }

internal static string FieldName(Expression<Func<IPLookupResult, object>> expression)
{
var propName = expression.PropertyName();
var attribute = typeof(IPLookupResult)
.GetProperty(propName)
?.GetCustomAttributes(typeof(JsonPropertyAttribute), false)
.Single() as JsonPropertyAttribute;
?.GetCustomAttributes(typeof(JsonPropertyNameAttribute), false)
.Single() as JsonPropertyNameAttribute;

return attribute?.PropertyName ?? string.Empty;
return attribute?.Name ?? string.Empty;
}
}
}
}
8 changes: 4 additions & 4 deletions src/IPData/Models/Language.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace IPData.Models
{
public class Language
{
[JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)]
[JsonPropertyName("name")]
public string Name { get; set; }

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

[JsonProperty("code", NullValueHandling = NullValueHandling.Ignore)]
[JsonPropertyName("code")]
public string Code { get; set; }
}
}
Loading
Loading