added JSONMapper.Deserialize<T>(..), added JSONMapper.Deserialize(string..)
ln.build - build0.waldrennach.l--n.de build job pending Details

master 1.0.6
Harald Wolff 2020-12-18 21:17:59 +01:00
parent 492e232fa7
commit 02adec8cb8
3 changed files with 24 additions and 1 deletions

View File

@ -125,6 +125,16 @@ namespace ln.json.tests
}
[Test]
public void TestDeserialize()
{
Assert.IsTrue(JSONMapper.DefaultMapper.Deserialize("[\"A\",\"B\",\"C\"]", out string[] texts));
Assert.AreEqual(3, texts.Length);
Assert.AreEqual("A", texts[0]);
Assert.AreEqual("B", texts[1]);
Assert.AreEqual("C", texts[2]);
}
void TestPrimitiveMapping(object primitiveValue)
{
Type primitiveType = primitiveValue.GetType();

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Version>1.0.5</Version>
<Version>1.0.6</Version>
<Authors>Harald Wolff-Thobaben</Authors>
<Company>l--n.de</Company>
<Product>ln.json</Product>

View File

@ -182,6 +182,19 @@ namespace ln.json.mapping
return false;
}
public virtual bool Deserialize<T>(string jsonSource, out T v) => Deserialize(JSONParser.Parse(jsonSource), out v);
public virtual bool Deserialize<T>(JSONValue json, out T v)
{
if (Deserialize(json, typeof(T), out object o))
{
v = (T)o;
return true;
}
v = default;
return false;
}
public virtual bool Deserialize(string jsonSource, Type nativeType, out object o) => Deserialize(JSONParser.Parse(jsonSource), nativeType, out o);
public virtual bool Deserialize(JSONValue json, Type nativeType, out object o)
{
o = null;