diff --git a/ln.json.tests/JSONTests.cs b/ln.json.tests/JSONTests.cs index 27916f4..c0c5e43 100644 --- a/ln.json.tests/JSONTests.cs +++ b/ln.json.tests/JSONTests.cs @@ -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(); diff --git a/ln.json/ln.json.csproj b/ln.json/ln.json.csproj index 992f27f..22204d8 100644 --- a/ln.json/ln.json.csproj +++ b/ln.json/ln.json.csproj @@ -2,7 +2,7 @@ netcoreapp3.1 - 1.0.5 + 1.0.6 Harald Wolff-Thobaben l--n.de ln.json diff --git a/ln.json/mapping/JSONMapper.cs b/ln.json/mapping/JSONMapper.cs index 2f2307d..0c25a70 100644 --- a/ln.json/mapping/JSONMapper.cs +++ b/ln.json/mapping/JSONMapper.cs @@ -182,6 +182,19 @@ namespace ln.json.mapping return false; } + public virtual bool Deserialize(string jsonSource, out T v) => Deserialize(JSONParser.Parse(jsonSource), out v); + public virtual bool Deserialize(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;