Is possible optimize json.net schema with JSchemaValidatingReader to deserialize in object in same read of stream?

后端 未结 1 1817
渐次进展
渐次进展 2021-01-24 03:15

I\'m trying a poc. Is possible optimize json.net schema with JSchemaValidatingReader to deserialize in object in same read of stream?

In otherworld

stri         


        
相关标签:
1条回答
  • 2021-01-24 03:27

    Yes, JSchemaValidatingReader is a subclass of JsonReader, so you can use it to deserialize by passing it to JsonSerializer.Deserialize(JsonReader):

    using (var s = File.OpenText(@"c:\bigdata.json"))
    using (var baseReader = new JsonTextReader(s))
    using (var reader = new JSchemaValidatingReader(baseReader))
    {
        reader.Schema = schema;
        reader.ValidationEventHandler += (sender, args) => { Console.WriteLine(args.Message); };
    
        root = JsonSerializer.CreateDefault().Deserialize<RootObject>(reader);
    }
    

    Demo fiddle here.

    Related documentation: Validate JSON with JSchemaValidatingReader.

    0 讨论(0)
提交回复
热议问题