コード例 #1
0
        public void SerializeObject_without_type_serializes_to_json_using_CompactSerializerSettings()
        {
            // If Compact is being used then there should be no new lines
            var dog = new Dog(5, "spud", FurColor.Brindle);

            var json = CompactJsonSerializer.SerializeObject(dog);

            Assert.That(json, Is.EqualTo("{\"name\":\"spud\",\"furColor\":\"brindle\",\"dogTag\":\"my name is spud\",\"nickname\":null,\"age\":5}"));
        }
コード例 #2
0
        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"));
        }
コード例 #3
0
        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"));
        }
コード例 #4
0
ファイル: Factory.cs プロジェクト: DerekZiemba/UniEvents
        private bool LoadConfiguration()
        {
            Configuration result = null;

            if (System.IO.File.Exists(_configFilePath))
            {
                using (var fs = new FileStream(_configFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    using (var sr = new StreamReader(fs, Encoding.UTF8))
                        using (var jsreader = new Newtonsoft.Json.JsonTextReader(sr)) {
                            result = CompactJsonSerializer.Deserialize <Configuration>(jsreader);
                        }
            }
            _Config = result;
            return(true);
        }