C
C#4mo ago
~bfg

Struggling with JSON

Any Idea why does this operation makes half of the fields = null without any errors or anything, just half of the fields in the class become null without any real pattern
No description
25 Replies
JP
JP4mo ago
really would need to see the class being serialized and maybe the SerializerOptions printing the string form of a might also give hints as to whether the problem starts at the serialization phase, rather than the deserialization phase
~bfg
~bfgOP4mo ago
it serializes normally, I can send full json one sec
~bfg
~bfgOP4mo ago
here are options
No description
~bfg
~bfgOP4mo ago
custom converters just trying to things to work
~bfg
~bfgOP4mo ago
~bfg
~bfgOP4mo ago
this is json and basically json looks fine to me, it totally copies all fields just deserializer struggles
JP
JP4mo ago
do you have an example of which properties end up null? (assuming its always the same ones)
~bfg
~bfgOP4mo ago
yeap one sec, I have pretty wild one yes
~bfg
~bfgOP4mo ago
basically you can see here the Buildings one, but if we look at the province data it has literally same buildings list but in that case they normally deserialized
No description
No description
~bfg
~bfgOP4mo ago
but in provinces on the other hand there are other fields that got badly deserialized I just don't have any idea why this can happen
JP
JP4mo ago
crazy question, what if you make Buildings a list on CustomScenario (noting, that should not matter, but thats a difference lmao)
~bfg
~bfgOP4mo ago
it was before, the same happens i tried to change it to array and nothing changed
~bfg
~bfgOP4mo ago
it did not work though until I wrote this converter
No description
~bfg
~bfgOP4mo ago
which literally does nothing new
JP
JP4mo ago
does that mean it was always null before this converter, regardless of type?
~bfg
~bfgOP4mo ago
wdym? ohh, i see it threw errors )))
JP
JP4mo ago
asking for the specifics of
it did not work though until I wrote this converter
Because I'm surprised this required custom
~bfg
~bfgOP4mo ago
without it
JP
JP4mo ago
hmm, curious what those are
~bfg
~bfgOP4mo ago
nevermind it still works when I turned it off idk why I wrote it then probably was trying to make main property not null
JP
JP4mo ago
this is ending up one of those "oh god what is System.Text.Json doing?" things lol do you have a repo of this by chance?
~bfg
~bfgOP4mo ago
i have but it's private I can send you rider code with me link or zip of .cs files if you want
JP
JP4mo ago
never used code with me, but let's try it, sounds interesting
~bfg
~bfgOP4mo ago
one sec send in dm if it was autoblocked btw
JP
JP4mo ago
For future readers, evidently System.Text.Json will not access the backing fields of auto properties via reflection (by default? for overridden props? ever?), so if there is no set;-er, you're toast

Did you find this page helpful?