Closed marcpiechura closed 2 years ago
I'll be honest, I wouldn't have expected this to be a desired behavior 😄 I definitely won't make it a default behavior, but I guess it can be added as an option.
My use case is to store different documents in the same CosmosDB collection and then use those fields for filtering on certain types. I could use a discriminated Union with the different types as cases but that would complicate querying and processing those documents in external systems. So giving that as option would be good enough, but I can life with custom converters too, if you don’t want to support that scenario.
And btw. the default System.Text.Json Serializer does it ootb ;-)
And btw. the default System.Text.Json Serializer does it ootb ;-)
Sure, because C# doesn't have records, and private fields are a pretty unreliable default to guess what you actually want to serialize; so the best option then is to use properties. But with records, I feel like using record fields and only them is the most reasonable default.
Currently record members are ignored during serialization. I'm not sure if that's something you want to support, but if so, I thought I could at least provide the failing test. I've already tried to implement it myself but couldn't find a way without rewriting quite a bit of code, so maybe you've a better idea how to fix this issue. My workaround is currently to simply use a custom converter for the specific types.
Thanks.