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 diff --git a/src/LitJson/JsonMapper.cs b/src/LitJson/JsonMapper.cs index 5a0a436..5cd9268 100644 --- a/src/LitJson/JsonMapper.cs +++ b/src/LitJson/JsonMapper.cs @@ -779,10 +779,13 @@ private static void RegisterBaseImporters () return; } - if (obj is IDictionary) { + if (obj is IDictionary dictionary) { writer.WriteObjectStart (); - foreach (DictionaryEntry entry in (IDictionary) obj) { - writer.WritePropertyName ((string) entry.Key); + 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); } 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 () {