Skip to content
This repository has been archived by the owner on May 16, 2022. It is now read-only.

Alternative to Json.NET ResolvePropertyName #143

Open
DSilence opened this issue Jan 1, 2019 · 3 comments
Open

Alternative to Json.NET ResolvePropertyName #143

DSilence opened this issue Jan 1, 2019 · 3 comments

Comments

@DSilence
Copy link

DSilence commented Jan 1, 2019

I was wondering if there is any alternative to Json.NET ResolvePropertyName to be able to get properly cased property name from formatter instance.

@Tornhoof
Copy link

Tornhoof commented Jan 1, 2019

Manual annotation like [DataMember(Name = "foo")]

@DSilence
Copy link
Author

DSilence commented Jan 2, 2019

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

@Tornhoof
Copy link

Tornhoof commented Jan 2, 2019

Thank you for your explanation, I don't think I've seen the functionality you need either.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants