示例#1
0
        public void LargeModeDeserialize()
        {
            var sharedDictionary = new SharedDictionary(new SystemTextJsonSerializer(SerializeMode.LargeObject), null, null);

            sharedDictionary.SetProperty("key1", "string");
            sharedDictionary.SetProperty("key2", 1);
            byte[] bytes = sharedDictionary.RawExport();
            Assert.AreEqual(Encoding.UTF8.GetString(bytes), JsonConstant.LargeModeJson);
        }
示例#2
0
        public void ShortModeDeserialize()
        {
            var sharedDictionary = new SharedDictionary(SpanJsonSerializer.Create(SerializeMode.ShortObject), null, null);

            sharedDictionary.SetProperty("key1", "string");
            sharedDictionary.SetProperty("key2", 1);
            byte[] bytes = sharedDictionary.RawExport();
            Assert.AreEqual(Encoding.UTF8.GetString(bytes), JsonConstant.ShortModeJson);
        }
示例#3
0
        public void LargeModeNullValue()
        {
            var sharedDictionary = new SharedDictionary(new SystemTextJsonSerializer(SerializeMode.LargeObject), null, null);

            sharedDictionary.SetProperty <int?>("nullableInt", null);
            sharedDictionary.SetProperty <string?>("nullableString", null);

            byte[] binary = sharedDictionary.RawExport();
            sharedDictionary.ClearProperty();
            Assert.AreEqual(0, sharedDictionary.PropertyCount);
            sharedDictionary.RawImport(binary);

            Assert.AreEqual(null, sharedDictionary.GetProperty <int?>("nullableInt"));
            Assert.AreEqual(null, sharedDictionary.GetProperty <string?>("nullableString"));
        }