public async Task CompareJsonDeserializePerformance() { var json = Jsonizer.Serialize(Item); var r0 = await Benchmark.Run(() => Jsonizer.Deserialize <TestItem0>(json)); json = Newtonsoft.Json.JsonConvert.SerializeObject(Item); var r1 = await Benchmark.Run(() => Newtonsoft.Json.JsonConvert.DeserializeObject <TestItem0>(json)); json = System.Text.Json.JsonSerializer.Serialize(Item); var r2 = await Benchmark.Run(() => System.Text.Json.JsonSerializer.Deserialize <TestItem0>(json)); var stats = new StatsBuilder() .Add(typeof(Jsonizer).FullName, r0) .Add(typeof(Newtonsoft.Json.JsonConvert).FullName, r1) .Add(typeof(System.Text.Json.JsonSerializer).FullName, r2) .ToString(); Console.WriteLine(stats); Assert.IsTrue(r0.PerSecond > r1.PerSecond); }
public static async Task <List <NugetQueryData> > GetPackages(string query) { var packages = new List <NugetQueryData>(); var flurl = "https://azuresearch-usnc.nuget.org/query" .SetQueryParams(new { q = query, take = 0, }); var json = await flurl.GetStringAsync(); var expected = Jsonizer.Deserialize <NugetQueryResponse>(json).totalHits; const int take = 100; var relevance = expected.ToDouble(); for (var skip = 0; skip < expected; skip += take) { json = await flurl.SetQueryParams(new { q = query, skip, take, }) .GetStringAsync(); var response = Jsonizer.Deserialize <NugetQueryResponse>(json); foreach (var d in response.data) { packages.Add(new NugetQueryData { Id = d.id, Relevance = (relevance-- / expected).ToPercentage(), TotalDownloads = d.totalDownloads, Version = d.version, Verified = d.verified, Authors = string.Join(", ", d.authors), Description = d.description, }); } } if (packages.Count != expected) { throw new Exception($"packages.Count:{packages.Count} != expected:{expected}"); } return(packages); }
public void NonStandardEnumValue() { var item = Jsonizer.Deserialize <TestItem1>("{\"Type\":\"test/2\"}"); Assert.AreEqual(TestEnum0.test2, item.Type); }
public void NullToNumber() { var item = Jsonizer.Deserialize <TestItem2>("{\"Amount\":null}"); Assert.AreEqual(0m, item.Amount); }
public void StringToNumber() { var item = Jsonizer.Deserialize <TestItem2>("{\"Amount\":\"1234.5678\"}"); Assert.AreEqual(1234.5678m, item.Amount); }