So I am trying to read in a serialized JSON file. So a part of my code currently looks like this
using (Stream input = File.OpenRead(openDialog.FileName))
using (BinaryReader reader = new BinaryReader(input))
This is part of a larger project. Per another StackOverflow post I have created my own Converter to deserialize my objects of the correct type, and I am realizing the read method for the custom type converter class uses Utf8JsonReader to read in the JSON. So my question is this, how can I achieve something like:
using Utf8JsonReader reader = new Utf8JsonReader(input))
So that I can pass in the input stream from the file system? I have looked at the the other SO post that is supposed to answer this, but it made me more confused. So that I can achieve this:
using (Stream input = File.OpenRead(openDialog.FileName))
//reader solution here
var options = new JsonSerializerOptions
{
Converters = { new BaseClassConverter() },
};
MyObject = JsonSerializer.Deserialize<BaseClass>(reader.GetString(), options);
Is this possible?