public ActionResult GetList()
        {
            var           noteSrv = StaticServiceFactory.Create <IDashboardNoteService>();
            var           notes   = noteSrv.GetVisibleNotesByCurrentUser();
            JilSerializer ser     = new JilSerializer();

            return(Content(ser.SerializeToString(notes), "application/json"));
        }
Пример #2
0
        public void Setup()
        {
            var jsonNetOptions = new JsonSerializerSettings
            {
                Formatting = Formatting.None,
                Converters = new JsonConverter[] {
                    new IsoDateTimeConverter {
                        DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
                    },
                    new LongToStringConverter(),
                },

                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                NullValueHandling     = NullValueHandling.Ignore
            };

            var serializeOptions = new JsonSerializerOptions
            {
                WriteIndented               = false,
                IgnoreNullValues            = false,
                PropertyNameCaseInsensitive = true,
                Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
            };

            serializeOptions.Converters.Add(new ImplicitInt64Converter());
            serializeOptions.Converters.Add(new ImplicitUInt64Converter());
            serializeOptions.Converters.Add(new ImplicitDateTimeConverter());
            serializeOptions.Converters.Add(new ImplicitDateTimeOffsetConverter());

            var deserializeOptions = new JsonSerializerOptions
            {
                WriteIndented               = false,
                IgnoreNullValues            = true,
                PropertyNameCaseInsensitive = true,
                Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
            };

            deserializeOptions.Converters.Add(new ImplicitInt16Converter());
            deserializeOptions.Converters.Add(new ImplicitUInt16Converter());
            deserializeOptions.Converters.Add(new ImplicitInt32Converter());
            deserializeOptions.Converters.Add(new ImplicitUInt32Converter());
            deserializeOptions.Converters.Add(new ImplicitInt64Converter());
            deserializeOptions.Converters.Add(new ImplicitUInt64Converter());
            deserializeOptions.Converters.Add(new ImplicitDecimalConverter());
            deserializeOptions.Converters.Add(new ImplicitDoubleConverter());
            deserializeOptions.Converters.Add(new ImplicitSingleConverter());
            deserializeOptions.Converters.Add(new ImplicitByteConverter());
            deserializeOptions.Converters.Add(new ImplicitSByteConverter());
            deserializeOptions.Converters.Add(new ImplicitDateTimeConverter());
            deserializeOptions.Converters.Add(new ImplicitDateTimeOffsetConverter());

            serializeToStringObject = new
            {
                int16    = 111.ToString(),
                uint16   = ushort.MaxValue.ToString(),
                int32    = int.MaxValue.ToString(),
                uint32   = uint.MaxValue.ToString(),
                int32N   = "".ToString(),
                int64    = 12321.ToString(),
                uint64   = ulong.MaxValue.ToString(),
                boolean  = true,
                decimalV = decimal.MaxValue.ToString(),
                doubleV  = "1.123445767",
                floatV   = "1.1111",
                byteV    = byte.MaxValue.ToString(),
                sbyteV   = sbyte.MaxValue.ToString(),
                charV    = 'c',
                date     = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                date1    = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                arr      = new string[] { "a", "b" },
                TestEnum = TestEnum.Approved
            };

            jsonFromString = JsonConvert.SerializeObject(serializeToStringObject, jsonNetOptions);

            serializeToStringClass = (TestClass)JsonConvert.DeserializeObject(jsonFromString, typeof(TestClass), jsonNetOptions);

            jsonNetSerializer  = new JsonNetSerializer(jsonNetOptions);
            textJsonSerializer = new TextJsonSerializer(serializeOptions, deserializeOptions);
            jilSerializer      = new JilSerializer();

            dataContractSerializer = new DataContractSerializer();
#if !NET5_0
            binarySerializer = new BinarySerializer();
#endif
            protoBufSerializer = new ProtoBufSerializer();

            NetSerializer.Serializer instance = new NetSerializer.Serializer(new[] { typeof(TestClass) });
            netSerializer = new NETSerializer(instance);

            dataContractFromString = dataContractSerializer.SerializeToString(serializeToStringClass);
#if !NET5_0
            binaryFromString = binarySerializer.SerializeToString(serializeToStringClass);
#endif
            protoBufFromString      = protoBufSerializer.SerializeToString(serializeToStringClass);
            netSerializerFromString = netSerializer.SerializeToString(serializeToStringClass);

            jilFromString = jilSerializer.SerializeToString(serializeToStringClass);
        }
Пример #3
0
 public void SerializeToString_Jil()
 {
     jilSerializer.SerializeToString(serializeToStringObject);
 }
Пример #4
0
        private void CompareSerializers <T>(T obj, int runs)
        {
            //warm-up

#if NETFULL || NETCOREAPP3_1
            jilserializer.SerializeToString(obj);
            using (MemoryStream mem = new MemoryStream())
            {
                binaryserializer.Serialize(obj, mem);
            }

            using (MemoryStream mem = new MemoryStream())
            {
                datacontractserializer.Serialize(obj, mem);
            }
#endif

#if NETFULL
            using (MemoryStream mem = new MemoryStream())
            {
                soapserializer.Serialize(obj, mem);
            }
#endif

            var netserializer = SerializerFactory.Get("NET");
            using (MemoryStream mem = new MemoryStream())
            {
                netserializer.Serialize(obj, mem);
            }

            jsonnetserializer.SerializeToString(obj);
            textjsonserializer.SerializeToString(obj);

            using (MemoryStream mem = new MemoryStream())
            {
                protobufserializer.Serialize(obj, mem);
            }


            xmlserializer.SerializeToString(obj);

            var keys = serializer.Keys.ToList();

#if NETFULL || NETCOREAPP3_1
            serializer["Jil"].Act = () =>
            {
                GC.Collect(2, GCCollectionMode.Forced, blocking: true);
                serializer["Jil"].Score = Helper.AverageRuntime(() =>
                {
                    jilserializer.SerializeToString(obj);
                }, runs);
            };
            serializer["Binary"].Act = () =>
            {
                GC.Collect(2, GCCollectionMode.Forced, blocking: true);
                serializer["Binary"].Score = Helper.AverageRuntime(() =>
                {
                    using (MemoryStream mem = new MemoryStream())
                    {
                        binaryserializer.Serialize(obj, mem);
                    }
                }, runs);
            };

            serializer["DataContract"].Act = () =>
            {
                GC.Collect(2, GCCollectionMode.Forced, blocking: true);
                serializer["DataContract"].Score = Helper.AverageRuntime(() =>
                {
                    using (MemoryStream mem = new MemoryStream())
                    {
                        datacontractserializer.Serialize(obj, mem);
                    }
                }, runs);
            };
#endif

#if NETFULL
            serializer["Soap"].Act = () =>
            {
                GC.Collect(2, GCCollectionMode.Forced, blocking: true);
                serializer["Soap"].Score = Helper.AverageRuntime(() =>
                {
                    using (MemoryStream mem = new MemoryStream())
                    {
                        soapserializer.Serialize(obj, mem);
                    }
                }, runs);
            };
#endif

            serializer["NET"].Act = () =>
            {
                GC.Collect(2, GCCollectionMode.Forced, blocking: true);
                serializer["NET"].Score = Helper.AverageRuntime(() =>
                {
                    using (MemoryStream mem = new MemoryStream())
                    {
                        netserializer.Serialize(obj, mem);
                    }
                }, runs);
            };

            serializer["Json"].Act = () =>
            {
                GC.Collect(2, GCCollectionMode.Forced, blocking: true);
                serializer["Json"].Score = Helper.AverageRuntime(() =>
                {
                    jsonnetserializer.SerializeToString(obj);
                }, runs);
            };

            serializer["TextJson"].Act = () =>
            {
                GC.Collect(2, GCCollectionMode.Forced, blocking: true);
                serializer["TextJson"].Score = Helper.AverageRuntime(() =>
                {
                    textjsonserializer.SerializeToString(obj);
                }, runs);
            };

            serializer["Xml"].Act = () =>
            {
                GC.Collect(2, GCCollectionMode.Forced, blocking: true);
                serializer["Xml"].Score = Helper.AverageRuntime(() =>
                {
                    xmlserializer.SerializeToString(obj);
                }, runs);
            };

            serializer["Protobuf"].Act = () =>
            {
                GC.Collect(2, GCCollectionMode.Forced, blocking: true);
                serializer["Protobuf"].Score = Helper.AverageRuntime(() =>
                {
                    using (MemoryStream mem = new MemoryStream())
                    {
                        protobufserializer.Serialize(obj, mem);
                    }
                }, runs);
            };

            keys.ForEach(k =>
            {
                serializer[k].Act();
            });
        }