public void DeserializeObject_without_type_deserializes_json_into_JObject_using_CompactSerializerSettings() { var dogJson = "{\"name\":\"Barney\",\"furColor\":\"brindle\",\"age\":10}"; var dog = CompactJsonSerializer.DeserializeObject(dogJson) as JObject; Assert.That(dog.Properties().Count(), Is.EqualTo(3)); Assert.That(dog["name"].ToString(), Is.EqualTo("Barney")); Assert.That(dog["age"].ToString(), Is.EqualTo("10")); Assert.That(dog["furColor"].ToString(), Is.EqualTo("brindle")); }
public void DeserializeObject_with_type_deserializes_json_using_CompactSerializerSettings() { // If Compact is being used then strict constructor matching will result in a Dog and not a Mouse var dogJson = "{\"name\":\"Barney\",\"furColor\":\"brindle\",\"age\":10}"; var dog = CompactJsonSerializer.DeserializeObject(dogJson, typeof(Animal)) as Dog; Assert.That(dog, Is.Not.Null); Assert.That(dog.Name, Is.EqualTo("Barney")); Assert.That(dog.Age, Is.EqualTo(10)); Assert.That(dog.FurColor, Is.EqualTo(FurColor.Brindle)); Assert.That(dog.DogTag, Is.EqualTo("my name is Barney")); }