ObjectToJson property naming policy #702
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Details
This pull request introduces an additional Naming Policy pin to the experimental
ObjectToJsonnode, enabling users to specify the casing of properties for a serialized C# object.Description
JsonPropertyNamingPolicyhelper enum to allow users to select a naming policy from an enum instead of using static operations that return these policies (19b84f0).GetJsonNamingPolicyFromEnumfunction that returns the appropriateJsonNamingPolicybased on aJsonPropertyNamingPolicy(our helper enum) input (0bdf356).Property Naming Policyinput pin of typeJsonPropertyNamingPolicytoObjectToJson. Internally, it sets thePropertyNamingPolicyof theJsonSerializeOptionusing the aforementionedGetJsonNamingPolicyFromEnumfunction. (bb8e1f7)Before change:
After change:
I have a few issues with the current state of this PR though:
JsonPropertyNamingPolicyis the best pick for the helper enum name. I picked this one as it was the most meaningful for the end-user I could think of.GetJsonNamingPolicyFromEnumis a static operation living in theXmlNodesclass. That obviously does not make much sense as this function deals with JSON, but I was not sure where to put it. Open to suggestions here!PascalCaseproperties. Unfortunately,JsonNamingPolicydoes not allow to pickPascalCase, as you can see on the .NET doc. What if the user actually wantsPascalCasethen? I was thinking about making the input pinOptional<JsonPropertyNamingPolicy>and only applyingSetPropertyNamingPolicyifHasValuereturns true, what do you think?.zipfile to this PR that shows the change in action. You can open this.vldocument with this branch ofVL.StandardLibsin your--package-repositories: JsonNamingPolicyPrTest.zipRelated Issue
None.
Motivation and Context
When serializing objects to send to a web API, incorrect property casing can cause the request to be rejected. This pull request addresses this issue by allowing users to choose a property naming policy, making sure the serialized object matches the API's expectations.
Types of changes
Checklist