public void TestMissingMemberHandlingForChildObjects()
        {
            string json = @"{""Data"":{""extensionData1"": [1,2,3]}}";
            ObjectWithExtendableChild e3 = JsonConvert.DeserializeObject <ObjectWithExtendableChild>(json, new JsonSerializerSettings {
                MissingMemberHandling = MissingMemberHandling.Error
            });
            JArray o1 = (JArray)e3.Data.Data["extensionData1"];

            Assert.AreEqual(JTokenType.Array, o1.Type);
        }
Beispiel #2
0
        public void TestMissingMemberHandlingForChildObjectsWithInvalidData()
        {
            string json = @"{""InvalidData"":{""extensionData1"": [1,2,3]}}";

            try
            {
                ObjectWithExtendableChild e3 = JsonConvert.DeserializeObject <ObjectWithExtendableChild>(json, new JsonSerializerSettings {
                    MissingMemberHandling = MissingMemberHandling.Error
                });
                Assert.Fail("an exception was expected due to MissingMemberHandling.Error, and no place to Deserialize InvalidData to");
            }
            catch (JsonSerializationException)
            {
                Assert.Pass();
            }
        }