Example #1
0
        private static JsonSerializerOptions CreateOptions(JsonSerializerOptions options)
        {
            options ??= new JsonSerializerOptions();
            options.AddJsonApi();

            return(options);
        }
Example #2
0
        public void Serializing()
        {
            var options = new JsonSerializerOptions();

            options.AddJsonApi();

            for (var i = 0; i < 100000; i++)
            {
                JsonSerializer.Serialize(data.Value, data.Type, options);
            }
        }
Example #3
0
        public void Deserializing()
        {
            var options = new JsonSerializerOptions();

            options.AddJsonApi();

            for (var i = 0; i < 100000; i++)
            {
                JsonSerializer.Deserialize(data.JsonApiBytes, data.Type, options);
            }
        }
        public void InsertedResourceConverterIsCalled()
        {
            var options   = new JsonSerializerOptions();
            var converter = new ResourceConverter();

            options.AddJsonApi();
            options.Converters.Insert(0, converter);

            Json.Deserialize <Article>(options);

            Assert.True(converter.ReadCalled);
        }
        public void AppendedResourceConverterNeverCalled()
        {
            var options   = new JsonSerializerOptions();
            var converter = new ResourceConverter();

            options.AddJsonApi();
            options.Converters.Add(converter);

            Json.Deserialize <Article>(options);

            Assert.False(converter.ReadCalled);
        }
Example #6
0
        private static JsonSerializerOptions CreateOptions(JsonSerializerOptions options)
        {
            options ??= new JsonSerializerOptions();

            try
            {
                options.WriteIndented = true;
                options.AddJsonApi();
            }
            catch (InvalidOperationException)
            {
            }

            return(options);
        }