From 5cf9d811d08ce1797a0775205a8c8ac45a6add5e Mon Sep 17 00:00:00 2001 From: Mattias Karlsson Date: Thu, 27 Sep 2018 17:19:45 +0200 Subject: [PATCH 1/4] Fixed csproj casing --- build.cake | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/build.cake b/build.cake index 8177dff..1c9e264 100644 --- a/build.cake +++ b/build.cake @@ -18,6 +18,8 @@ string version = null, semVersion = null, milestone = null; +FilePath litjsonProjectPath = "./src/LitJson/LitJSON.csproj"; + /////////////////////////////////////////////////////////////////////////////// // SETUP / TEARDOWN /////////////////////////////////////////////////////////////////////////////// @@ -129,9 +131,9 @@ Task("Test-SourceLink") .IsDependentOn("Build") .WithCriteria(IsRunningOnWindows()) .Does(() => { - foreach(var asssembly in GetFiles("./src/LitJSON/bin/" + configuration + "/**/*.dll")) + foreach(var asssembly in GetFiles("./src/LitJson/bin/" + configuration + "/**/*.dll")) { - DotNetCoreTool("./src/LitJSON/LitJSON.csproj", "sourcelink", $"test {asssembly}"); + DotNetCoreTool(litjsonProjectPath.FullPath, "sourcelink", $"test {asssembly}"); } }); @@ -139,7 +141,7 @@ Task("Package") .IsDependentOn("Test") .IsDependentOn("Test-SourceLink") .Does(() => { - DotNetCorePack("./src/LitJSON/LitJSON.csproj", + DotNetCorePack(litjsonProjectPath.FullPath, new DotNetCorePackSettings { Configuration = configuration, NoBuild = true, From f8df806eec20f498ee22a241152b919a32e7d041 Mon Sep 17 00:00:00 2001 From: Stephen Hogan Date: Fri, 28 Sep 2018 14:13:23 -0600 Subject: [PATCH 2/4] Added the ability to remove elements from JsonData objects as well as JsonData arrays. --- src/LitJson/JsonData.cs | 19 ++++++++++++++++++ test/JsonDataTest.cs | 43 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/src/LitJson/JsonData.cs b/src/LitJson/JsonData.cs index ca4da38..e89e4b1 100644 --- a/src/LitJson/JsonData.cs +++ b/src/LitJson/JsonData.cs @@ -819,6 +819,25 @@ public int Add (object value) return EnsureList ().Add (data); } + public bool Remove(object obj) + { + json = null; + if(IsObject) + { + JsonData value = null; + if (inst_object.TryGetValue((string)obj, out value)) + return inst_object.Remove((string)obj) && object_list.Remove(new KeyValuePair((string)obj, value)); + else + throw new KeyNotFoundException("The specified key was not found in the JsonData object."); + } + if(IsArray) + { + return inst_array.Remove(ToJsonData(obj)); + } + throw new InvalidOperationException ( + "Instance of JsonData is not an object or a list."); + } + public void Clear () { if (IsObject) { diff --git a/test/JsonDataTest.cs b/test/JsonDataTest.cs index e9e3782..8806535 100644 --- a/test/JsonDataTest.cs +++ b/test/JsonDataTest.cs @@ -231,6 +231,49 @@ public void NullValue () Assert.AreEqual (json, data.ToJson ()); } + [Test] + public void RemoveValueFromObject() + { + string json = "{\"test1\":1}"; + + JsonData data = new JsonData(); + data["test1"] = 1; + data["test2"] = 2; + data.Remove("test2"); + + Assert.AreEqual(json, data.ToJson()); + } + + [Test] + public void RemoveValueFromNestedObject() + { + string json = "{\"test1\":{\"test3\":3}}"; + + JsonData data = new JsonData(); + data["test1"] = new JsonData(); + data["test1"]["test2"] = 2; + data["test1"]["test3"] = 3; + data["test1"].Remove("test2"); + + Assert.AreEqual(json, data.ToJson()); + } + + [Test] + public void RemoveValueFromArray() + { + string json = "[\"test1\",2.0]"; + + JsonData data = new JsonData(); + data.Add("test1"); + data.Add("test2"); + data.Remove("test2"); + data.Add(1); + data.Add(2.0); + data.Remove(1); + + Assert.AreEqual(json, data.ToJson()); + } + [Test] public void PropertiesOrderTest () { From 4828d2eee5b23b3596b52a4b57bf4b5d37c3b5c3 Mon Sep 17 00:00:00 2001 From: Ken Hung Date: Wed, 18 Sep 2019 17:10:43 +0800 Subject: [PATCH 3/4] Fix DateTimeOffset support. --- src/LitJson/JsonMapper.cs | 5 ++++ test/JsonMapperTest.cs | 48 +++++++++++++++++++++++---------------- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/LitJson/JsonMapper.cs b/src/LitJson/JsonMapper.cs index 0fc106a..5a0a436 100644 --- a/src/LitJson/JsonMapper.cs +++ b/src/LitJson/JsonMapper.cs @@ -603,6 +603,11 @@ private static void RegisterBaseExporters () delegate (object obj, JsonWriter writer) { writer.Write ((ulong) obj); }; + + base_exporters_table[typeof(DateTimeOffset)] = + delegate (object obj, JsonWriter writer) { + writer.Write(((DateTimeOffset)obj).ToString("yyyy-MM-ddTHH:mm:ss.fffffffzzz", datetime_format)); + }; } private static void RegisterBaseImporters () diff --git a/test/JsonMapperTest.cs b/test/JsonMapperTest.cs index f4426c5..17829a9 100644 --- a/test/JsonMapperTest.cs +++ b/test/JsonMapperTest.cs @@ -162,15 +162,16 @@ public class UiWindow public class ValueTypesTest { - public byte TestByte; - public char TestChar; - public DateTime TestDateTime; - public decimal TestDecimal; - public sbyte TestSByte; - public short TestShort; - public ushort TestUShort; - public uint TestUInt; - public ulong TestULong; + public byte TestByte; + public char TestChar; + public DateTime TestDateTime; + public decimal TestDecimal; + public sbyte TestSByte; + public short TestShort; + public ushort TestUShort; + public uint TestUInt; + public ulong TestULong; + public DateTimeOffset TestDateTimeOffset; } public class NullableTypesTest @@ -399,13 +400,17 @@ public void ExportValueTypesTest () test.TestUShort = 30000; test.TestUInt = 90000000; test.TestULong = 0xFFFFFFFFFFFFFFFF; // = =18446744073709551615 + test.TestDateTimeOffset = + new DateTimeOffset(2019, 9, 18, 16, 47, + 50, 123, TimeSpan.FromHours(8)).AddTicks(4567); string json = JsonMapper.ToJson (test); string expected = "{\"TestByte\":200,\"TestChar\":\"P\",\"TestDateTime\":" + "\"12/22/2012 00:00:00\",\"TestDecimal\":10.333," + "\"TestSByte\":-5,\"TestShort\":1024,\"TestUShort\":30000" + - ",\"TestUInt\":90000000,\"TestULong\":18446744073709551615}"; + ",\"TestUInt\":90000000,\"TestULong\":18446744073709551615" + + ",\"TestDateTimeOffset\":\"2019-09-18T16:47:50.1234567+08:00\"}"; Assert.AreEqual (expected, json); } @@ -825,15 +830,16 @@ public void ImportValueTypesTest () { string json = @" { - ""TestByte"": 200, - ""TestChar"": 'P', - ""TestDateTime"": ""12/22/2012 00:00:00"", - ""TestDecimal"": 10.333, - ""TestSByte"": -5, - ""TestShort"": 1024, - ""TestUShort"": 30000, - ""TestUInt"": 90000000, - ""TestULong"": 18446744073709551615 + ""TestByte"": 200, + ""TestChar"": 'P', + ""TestDateTime"": ""12/22/2012 00:00:00"", + ""TestDecimal"": 10.333, + ""TestSByte"": -5, + ""TestShort"": 1024, + ""TestUShort"": 30000, + ""TestUInt"": 90000000, + ""TestULong"": 18446744073709551615, + ""TestDateTimeOffset"": ""2019-09-18T16:47:50.1234567+08:00"" }"; ValueTypesTest test = JsonMapper.ToObject (json); @@ -848,6 +854,10 @@ public void ImportValueTypesTest () Assert.AreEqual (30000, test.TestUShort, "A7"); Assert.AreEqual (90000000, test.TestUInt, "A8"); Assert.AreEqual (18446744073709551615L, test.TestULong, "A9"); + Assert.AreEqual( + new DateTimeOffset(2019, 9, 18, 16, 47, + 50, 123, TimeSpan.FromHours(8)).AddTicks(4567), + test.TestDateTimeOffset, "A10"); } [Test] From 033f8bc32fabb9691d34ab77535c2f10e7323d3d Mon Sep 17 00:00:00 2001 From: Mattias Karlsson Date: Wed, 18 Sep 2019 16:13:58 +0200 Subject: [PATCH 4/4] Fix package license warning --- src/LitJson/LitJSON.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LitJson/LitJSON.csproj b/src/LitJson/LitJSON.csproj index 62d0992..10738d5 100644 --- a/src/LitJson/LitJSON.csproj +++ b/src/LitJson/LitJSON.csproj @@ -23,7 +23,7 @@ It's quick and lean, without external dependencies. The authors disclaim copyright to this source code. Leonardo Boshell, Mattias Karlsson and contributors Leonardo Boshell, Mattias Karlsson and contributors - https://github.com/LitJSON/litjson/blob/develop/COPYING + Unlicense https://litjson.net/assets/img/logo.png https://github.com/LitJSON/litjson git