❔ How to deserialize correctly
Hi, I have the following records :
this is a little bit weird (the name Product is used twice), because unfortunately the records are used to deserialize objects returned from an external API that returns a list either empty or have the following format:
To deserialize, I am using
The problem is that I don't know how to do this properly in order not to have the warnings. Any idea ?
5 Replies
In .NET 7 you can make those properties
required
In earlier versions, you can initialize them with = default!;
Okay thanks. What about the
init
?
Now the compiler is suggesting that it's never user and suggest me to refactor to something like public string Procudt => default!
but the Deserialization does not work in this case
PS: I am using .NET 6Just ignore it
Warnings are just that, warnings
Not errors
The IDE can't know of every scenario, especially if it involves reflections and stuff. So it just can't know those setters are actually used
okay got it, thanks !
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.