Skip to content

Conversation

@t00
Copy link

@t00 t00 commented May 3, 2021

Currently camelCase naming is applied to all JSON properties, regardless of the case used in JsonProperty("CustomCASEProperty").
The proposed fix allows serialized JSON to contain arbitrary case names in custom properties.

Examples contain expected camelCase names so there should be no compatibility issues although if someone used the library and depended on changing MyCustomProperty to myCustomProperty, they will have to update custom names.

Hopefully you can include this change as otherwise use cases like mine, requiring specific case in JSON messages, will need to rely on a hack similar to the one below:

 private static void ConfigureJsonSerializer() { var settingsProperty = typeof(CorePush.Utils.JsonHelper).GetTypeInfo() .GetFields(BindingFlags.Static | BindingFlags.NonPublic) .FirstOrDefault(x => "settings".Equals(x.Name, StringComparison.OrdinalIgnoreCase)); if (settingsProperty != null && settingsProperty.GetValue(null) is JsonSerializerSettings settings) { settings.ContractResolver = new CamelCasePropertyNamesContractResolver { NamingStrategy = new CamelCaseNamingStrategy(true, false) }; } } 
@andrei-m-code
Copy link
Owner

Thanks for this PR. I'm migrating to System.Text.Json soon so this won't be necessary. We'll leave the version 3.x.x to work as is and starting from 4.x.x we'll use System.Text.Json without JsonHelper.

@t00
Copy link
Author

t00 commented Sep 9, 2021

Thanks for clarifying plans to migrate to System.Text.Json which is great news considering Newtonsoft.Json is a heavy dependency.

Will you make sure that serializer settings will be configurable just for net-core-push-notifications instead of using global settings which could be different to push?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants