Replies: 1 comment
-
There is See also here: https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/preserve-references If that does not allow you to get the results (or implement) what you need, i am afraid you need to explain in more concrete detail the kind and nature of the .NET object graph you are trying to serialize and what the resulting json is expected to look like as far as the problem at hand is concerned. |
Beta Was this translation helpful? Give feedback.
-
I would like to build a solution that can load and store collections of objects from and to JSON files. The whole graph consists of multiple collections, each for one type, and the collections can have many items. The objects themselves can have subobjects that are part of the object (document, in NoSQL-speak). But there can also be references between objects, and these cannot simply be serialised as with the existing methods. Instead, I want them to be replaced with the object ID instead. When reading the JSON, they need to be resolved to the existing objects again. And a few other features that I have on my list, like nicely handling derived types within an object collection.
Anyway, I found it to be promising if I could base my work on the existing JSON source generator code. I might not be able to understand it, but I'd at least give it a try. The generated code already looks very complicated. But since I only want to extend it a bit, it might work. Unfortunately, I couldn't find that code anywhere. Where is it? And is it possible to use and extend it with custom features? Of course I wouldn't want to have a dead fork of it but be able to upgrade it to .NET 9 and whatever improvements it gets.
I have already looked into JsonConverters but they are far too limited and cannot solve my problems.
I'm specifically interested in source generators because 1. I need them anyway because I'm targeting AOT, and 2. they should be able to take away much repetitive typing work that can be automated.
PS: Please excuse my limited terminology here. I don't know how exactly you call all these things. I'll try to improve as I learn the differences.
Beta Was this translation helpful? Give feedback.
All reactions