Skip to content
This repository was archived by the owner on Jan 15, 2023. It is now read-only.

Allow to change serialization naming policy #209

Closed
Jluil opened this issue Jun 11, 2020 · 5 comments
Closed

Allow to change serialization naming policy #209

Jluil opened this issue Jun 11, 2020 · 5 comments

Comments

@Jluil
Copy link

Jluil commented Jun 11, 2020

Allow to change serialization naming policy to JsonNamingPolicy.CamelCase.
This behavior is now standard for .NET core services, where .NET has PascalCase properties and client web app uses CamelCase properties.

@mattkol
Copy link
Member

mattkol commented Jun 13, 2020

@Jluil is the suggestion to make JsonNamingPolicy.CamelCase the default globally or allow to make it configurable?

Not sure we can force a default globally the way we are setup currently. I have not looked closely, there may be a way.

Just FYI the next version of Chromely will use Microsoft.Extensions.DependencyInjection. I have looked at it closely and it seems light enough for Chromely. So this will replace - Caliburn.Light Container.

So with this, change should be easy for developers to make.

We just need to create bandwidth for that.

Good point! 👍

@Jluil
Copy link
Author

Jluil commented Jun 14, 2020

Hey, thanks for the response.
It would be ideal if the options were configurable, but I think CamelCase policy could even be default.
I briefly looked through the codes and currently SerializationOptions are static within some utility class. Having them injected/configurable would be nice.
I really like the project and I'm currently testing the server-client communication. I might a few more suggestions.. hope you don't mind:)

@mattkol
Copy link
Member

mattkol commented Jun 14, 2020

@Jluil by Utility class, you mean int the Extension method? Sure, that can be improved. Thanks for pointing it out.

Having them injected/configurable would be nice.

This needs to be thought through. The use of System.Text.Json is more of a suggestive use rather than a standard. Chromely more or less uses it in default classes. Those classes are replaceable and customizable. So in essence the serializing library can be replaced. Developers are not necessarily tied to System.Text.Json. They can use any serializing library.

Like I mentioned earlier, we will see how all these fit in when we move to Microsoft.Extensions.DependencyInjection.

Suggestions are always welcome.

Thanks.

@Jluil
Copy link
Author

Jluil commented Jun 15, 2020

It's really nice that .NET has it's own Json serializer that can do stuff like PascalCase to camelCase conversion by simply changing: PropertyNamingPolicy = JsonNamingPolicy.CamelCase.

@FrankPfattheicher
Copy link
Member

For Newtonsoft.JSON this could be

JsonConvert.DefaultSettings = () => new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
                {
                    NamingStrategy = new CamelCaseNamingStrategy()
                } 
            };

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

3 participants