Beispiel #1
0
        public override IReadOnlyList <string> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
            JsonTokenType tokenType = reader.TokenType;

            if (tokenType != JsonTokenType.StartArray)
            {
                throw new JsonException();
            }

            var list = new SimpleSegmentedList <string>();

            while (true)
            {
                reader.Read();
                tokenType = reader.TokenType;

                if (reader.TokenType == JsonTokenType.EndArray)
                {
                    break;
                }

                list.Add(reader.GetString());
            }

            return(list);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            SimpleSegmentedList <string> list = new SimpleSegmentedList <string>();

            int count = 8 * 1024 + 1;

            for (int i = 0; i < count; i++)
            {
                list.Add(i.ToString());
            }

            var data = new JsonData();

            data.Words = list;

            string text = JsonSerializer.Serialize(data);

            Console.WriteLine(data.Words);

#if DEBUG
            Console.WriteLine(text);
#endif
            {
                var data1 = JsonSerializer.Deserialize <JsonData0>(text);

                Console.WriteLine(data1.Words);
            }

            {
                var options = new JsonSerializerOptions
                {
                    Converters = { new IReadOnlyListConverter() }
                };

                var data2 = JsonSerializer.Deserialize <JsonData>(text, options);

                Console.WriteLine(data2.Words);

#if DEBUG
                foreach (var w in data2.Words)
                {
                    Console.WriteLine(w);
                }

                Console.WriteLine("done");
#endif
            }

            PerfTest(text);
        }