Fix mapping bug for byte values, add test

master
Harald Wolff 2020-12-12 21:25:46 +01:00
parent f8e055c3c8
commit cf0cd55be8
2 changed files with 10 additions and 4 deletions

View File

@ -87,8 +87,6 @@ namespace ln.json.tests
TestEnumSerialization(testEnum3.C);
TestEnumSerialization(testEnum3.D);
TestEnumSerialization(testEnum3.E);
}
bool TestEnumSerialization(object enumValue)
@ -105,7 +103,15 @@ namespace ln.json.tests
return true;
}
[Test]
public void TestMapper()
{
byte b = 0x80;
Assert.IsTrue(JSONMapper.DefaultMapper.Serialize(b, out JSONValue jsonByte));
JSONMapper.DefaultMapper.Deserialize(jsonByte, typeof(byte), out object b2);
Assert.AreEqual(b,b2);
Assert.AreEqual(b.GetType(), b2.GetType());
}
}
}

View File

@ -259,7 +259,7 @@ namespace ln.json.mapping
{
DefaultMapper.Add(new JSONMapping(
typeof(byte),
(JSONMapper arg1, object arg2) => new JSONNumber((int)arg2),
(JSONMapper arg1, object arg2) => new JSONNumber((int)(byte)arg2),
(JSONMapper arg1, JSONValue arg2) => Decimal.ToByte(((JSONNumber)arg2).Decimal)
));
DefaultMapper.Add(new JSONMapping(