Skip to content

Commit

Permalink
Merge branch 'release/0.17.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
devlead committed Jan 21, 2021
2 parents 4c9ad30 + 62a43f7 commit 43291ff
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/LitJson/JsonMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ private static object ReadValue (Type inst_type, JsonReader reader)
list = new ArrayList ();
elem_type = inst_type.GetElementType ();
}

list.Clear();

while (true) {
Expand Down Expand Up @@ -829,10 +829,20 @@ private static void RegisterBaseImporters ()
if (obj is Enum) {
Type e_type = Enum.GetUnderlyingType (obj_type);

if (e_type == typeof (long)
|| e_type == typeof (uint)
|| e_type == typeof (ulong))
if (e_type == typeof (long))
writer.Write ((long) obj);
else if (e_type == typeof (uint))
writer.Write ((uint) obj);
else if (e_type == typeof (ulong))
writer.Write ((ulong) obj);
else if (e_type == typeof(ushort))
writer.Write ((ushort)obj);
else if (e_type == typeof(short))
writer.Write ((short)obj);
else if (e_type == typeof(byte))
writer.Write ((byte)obj);
else if (e_type == typeof(sbyte))
writer.Write ((sbyte)obj);
else
writer.Write ((int) obj);

Expand Down Expand Up @@ -920,7 +930,7 @@ public static T ToObject<T> (string json)

return (T) ReadValue (typeof (T), reader);
}

public static object ToObject(string json, Type ConvertType )
{
JsonReader reader = new JsonReader(json);
Expand Down
35 changes: 35 additions & 0 deletions test/JsonMapperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1099,5 +1099,40 @@ public void EmptyArrayInJsonDataTest()
string expectedJson = "{\"array\":[],\"name\":\"testName\"}";
Assert.AreEqual(toJsonResult, expectedJson);
}
public enum UshortEnum : ushort
{
Test = 0,
}
public enum ShortEnum : short
{
Test = 0,
}
public enum ByteEnum : byte
{
Test = 0,
}

public enum SbyteEnum : sbyte
{
Test = 0,
}

public class EnumWrapper
{
public UshortEnum ushortEnum;
public ShortEnum shortEnum;
public ByteEnum byteEnum;
public SbyteEnum sbyteEnum;
}

[Test]
public void shortAndByteBasedEnumToJsonTest()
{
var enumWrapper = new EnumWrapper();
Assert.DoesNotThrow(() =>
{
var json = JsonMapper.ToJson(enumWrapper);
});
}
}
}

0 comments on commit 43291ff

Please sign in to comment.