Skip to content

Commit b2109bb

Browse files
committed
Fixed issue 104 and added test. Changed method to use ToString instead of casting
1 parent 2d20227 commit b2109bb

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/LitJson/JsonMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ private static void WriteValue (object obj, JsonWriter writer,
782782
if (obj is IDictionary) {
783783
writer.WriteObjectStart ();
784784
foreach (DictionaryEntry entry in (IDictionary) obj) {
785-
writer.WritePropertyName ((string) entry.Key);
785+
writer.WritePropertyName (entry.Key.ToString());
786786
WriteValue (entry.Value, writer, writer_is_private,
787787
depth + 1);
788788
}

test/JsonMapperTest.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,22 @@ public void ExportEnumsTest ()
306306
Assert.AreEqual ("{\"FavouritePlanet\":1,\"Band\":9}", json);
307307
}
308308

309+
[Test]
310+
public void ExportEnumDictionaryTest()
311+
{
312+
Dictionary<Planets, int> planets = new Dictionary<Planets, int>();
313+
314+
planets.Add(Planets.Jupiter, 5);
315+
planets.Add(Planets.Saturn, 6);
316+
planets.Add(Planets.Uranus, 7);
317+
planets.Add(Planets.Neptune, 8);
318+
planets.Add(Planets.Pluto, 9);
319+
320+
string json = JsonMapper.ToJson(planets);
321+
322+
Assert.AreEqual("{\"Jupiter\":5,\"Saturn\":6,\"Uranus\":7,\"Neptune\":8,\"Pluto\":9}", json);
323+
}
324+
309325
[Test]
310326
public void ExportObjectTest ()
311327
{

0 commit comments

Comments
 (0)