Open DSilence opened 5 years ago
Manual annotation like [DataMember(Name = "foo")]
Thanks for the suggestion, but this will not work in my case. I'm working on porting NodaTime serialization library to UTF8Json. Some NodaTime types (e.g. Interval) must be serialized into custom objects, sample could be found here https://github.com/nodatime/nodatime.serialization/blob/master/src/NodaTime.Serialization.JsonNet/NodaDateIntervalConverter.cs#L41. Those objects should respect the global serialization rules which are configured for property name - ContractResolver in JsonNet case. Those rules should be set up by clients of the library and should NOT be hardcoded. For UTF8Json, the closest to "global" rules is StandardResolver, but as far as I understand it will only affect IL generated formatters for custom types, and there is no good way of accessing this configuration at formatter level. As of right now, I ended up creating a DTO to workaround this issue, but this is not ideal. https://github.com/DSilence/NodaTime.Serialization.Utf8Json/blob/develop/src/NodaTime.Serialization.Utf8Json/DS.NodaTime.Serialization.Utf8Json/NodaDateIntervalFormatter.cs
Thank you for your explanation, I don't think I've seen the functionality you need either.
I was wondering if there is any alternative to Json.NET ResolvePropertyName to be able to get properly cased property name from formatter instance.