C
C#5mo 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
JP5mo 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
~bfgOP5mo ago
it serializes normally, I can send full json one sec
~bfg
~bfgOP5mo ago
here are options
No description
~bfg
~bfgOP5mo ago
custom converters just trying to things to work
~bfg
~bfgOP5mo ago
~bfg
~bfgOP5mo ago
this is json and basically json looks fine to me, it totally copies all fields just deserializer struggles
JP
JP5mo ago
do you have an example of which properties end up null? (assuming its always the same ones)
~bfg
~bfgOP5mo ago
yeap one sec, I have pretty wild one yes
~bfg
~bfgOP5mo 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
~bfgOP5mo 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
JP5mo ago
crazy question, what if you make Buildings a list on CustomScenario (noting, that should not matter, but thats a difference lmao)
~bfg
~bfgOP5mo ago
it was before, the same happens i tried to change it to array and nothing changed
~bfg
~bfgOP5mo ago
it did not work though until I wrote this converter
No description
~bfg
~bfgOP5mo ago
which literally does nothing new
JP
JP5mo ago
does that mean it was always null before this converter, regardless of type?
~bfg
~bfgOP5mo ago
wdym? ohh, i see it threw errors )))
JP
JP5mo ago
asking for the specifics of
it did not work though until I wrote this converter
Because I'm surprised this required custom
~bfg
~bfgOP5mo ago
without it
JP
JP5mo ago
hmm, curious what those are
~bfg
~bfgOP5mo 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
JP5mo 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
~bfgOP5mo 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
JP5mo ago
never used code with me, but let's try it, sounds interesting
~bfg
~bfgOP5mo ago
one sec send in dm if it was autoblocked btw
JP
JP5mo 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?