From b2109bb54e10ae0fe796c86983ec454934135b5f Mon Sep 17 00:00:00 2001 From: grantfar Date: Sun, 13 Oct 2019 19:29:13 -0400 Subject: [PATCH 1/3] Fixed issue 104 and added test. Changed method to use ToString instead of casting --- src/LitJson/JsonMapper.cs | 2 +- test/JsonMapperTest.cs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/LitJson/JsonMapper.cs b/src/LitJson/JsonMapper.cs index 5a0a436..a54a8eb 100644 --- a/src/LitJson/JsonMapper.cs +++ b/src/LitJson/JsonMapper.cs @@ -782,7 +782,7 @@ private static void WriteValue (object obj, JsonWriter writer, if (obj is IDictionary) { writer.WriteObjectStart (); foreach (DictionaryEntry entry in (IDictionary) obj) { - writer.WritePropertyName ((string) entry.Key); + writer.WritePropertyName (entry.Key.ToString()); WriteValue (entry.Value, writer, writer_is_private, depth + 1); } diff --git a/test/JsonMapperTest.cs b/test/JsonMapperTest.cs index 17829a9..a980cfa 100644 --- a/test/JsonMapperTest.cs +++ b/test/JsonMapperTest.cs @@ -306,6 +306,22 @@ public void ExportEnumsTest () Assert.AreEqual ("{\"FavouritePlanet\":1,\"Band\":9}", json); } + [Test] + public void ExportEnumDictionaryTest() + { + Dictionary planets = new Dictionary(); + + planets.Add(Planets.Jupiter, 5); + planets.Add(Planets.Saturn, 6); + planets.Add(Planets.Uranus, 7); + planets.Add(Planets.Neptune, 8); + planets.Add(Planets.Pluto, 9); + + string json = JsonMapper.ToJson(planets); + + Assert.AreEqual("{\"Jupiter\":5,\"Saturn\":6,\"Uranus\":7,\"Neptune\":8,\"Pluto\":9}", json); + } + [Test] public void ExportObjectTest () { From 10431c5e589be99279dc55a8b949706f0b1a8dc5 Mon Sep 17 00:00:00 2001 From: grantfar Date: Mon, 14 Oct 2019 13:16:31 -0400 Subject: [PATCH 2/3] Made jsonmapper for dictionary use InvariantCulture --- src/LitJson/JsonMapper.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/LitJson/JsonMapper.cs b/src/LitJson/JsonMapper.cs index a54a8eb..5cd9268 100644 --- a/src/LitJson/JsonMapper.cs +++ b/src/LitJson/JsonMapper.cs @@ -779,10 +779,13 @@ private static void WriteValue (object obj, JsonWriter writer, return; } - if (obj is IDictionary) { + if (obj is IDictionary dictionary) { writer.WriteObjectStart (); - foreach (DictionaryEntry entry in (IDictionary) obj) { - writer.WritePropertyName (entry.Key.ToString()); + foreach (DictionaryEntry entry in dictionary) { + var propertyName = entry.Key is string key ? + key + : Convert.ToString(entry.Key, CultureInfo.InvariantCulture); + writer.WritePropertyName (propertyName); WriteValue (entry.Value, writer, writer_is_private, depth + 1); } From a90b59e33b13d2d57fcdb6305e6d59369a961aed Mon Sep 17 00:00:00 2001 From: Mattias Karlsson Date: Mon, 21 Oct 2019 17:09:44 +0200 Subject: [PATCH 3/3] Update to Cake 0.35.0 and .NET Core SDK 3.0.100 --- .travis.yml | 4 ++-- build.config | 4 ++-- global.json | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0191791..ffabc44 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,12 +13,12 @@ osx_image: xcode9.2 mono: - 4.4.2 -dotnet: 2.1.3 +dotnet: 3.0.100 before_install: - git fetch --unshallow # Travis always does a shallow clone, but GitVersion needs the full history including branches and tags - git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" - - git fetch origin + - git fetch origin script: - ./build.sh --target=Test \ No newline at end of file diff --git a/build.config b/build.config index fa6b8df..b60a637 100644 --- a/build.config +++ b/build.config @@ -1,3 +1,3 @@ #!/usr/bin/env bash -CAKE_VERSION=0.34.1 -DOTNET_VERSION=3.0.100-rc1-014190 +CAKE_VERSION=0.35.0 +DOTNET_VERSION=3.0.100 diff --git a/global.json b/global.json index f36e2ea..052baf7 100644 --- a/global.json +++ b/global.json @@ -3,6 +3,6 @@ "src" ], "sdk": { - "version": "3.0.100-rc1-014190" + "version": "3.0.100" } } \ No newline at end of file