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