✅ Extracting an object from a Utf8JsonReader
I'm currently writing my own JsonConverter, and I've got the writer bit working fine. (simplified example below)
However, I'm struggling a bit to do the opposite of this in
Read()
I have the Utf8JsonReader
object in Read()
, but the only thing that I can figure out is how to get a direct value from the reader, and can't get values by key from it.
What am I missing here?
Thanks4 Replies
I think I've figured this one out. It's a little less straight-forward than I'd hoped...
I ended up with this:
If I'm over-complicating this, I'd appreciate any pointers here
Looks roughly equivalent to the example here: https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/converters-how-to?pivots=dotnet-7-0#sample-factory-pattern-converter (you're not using a factory of course, but I don't think you need to)
How to write custom converters for JSON serialization - .NET
Learn how to create custom converters for the JSON serialization classes that are provided in the System.Text.Json namespace.
Although your serializer doesn't write a
{
but your deserializer expects one...Thanks - I'll have a look at that page