Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • This doesn't seem to deserialize when the list properties exist/have any data; in that case they get deserialized as nulls. Your example doesn't round trip (try deserializing the result of the original serialization). Any ideas? I really liked this approach but it's just not working -- I need an Array in my json source that is null to deserialize to an empty list, but one that has data to deserialize to that list with said data. Commented Feb 8, 2019 at 23:05
  • 1
    @pinkfloydx33 You're right-- you need to set ObjectCreationHandling to Replace for the round-trip to work correctly. I've amended my answer. Here is a fiddle to prove it works once this setting is added: dotnetfiddle.net/wsEyze Commented Feb 9, 2019 at 6:45
  • Cool, thanks! I thought I was going crazy originally until I tried your code verbatim and then attempted the round trip. Much appreciated Commented Feb 9, 2019 at 8:06