Skip to content

Conversation

@sebescudie
Copy link
Contributor

@sebescudie sebescudie commented Jul 18, 2025

PR Details

This pull request introduces an additional Naming Policy pin to the experimental ObjectToJson node, enabling users to specify the casing of properties for a serialized C# object.

Description

  • Introduces a static JsonPropertyNamingPolicy helper enum to allow users to select a naming policy from an enum instead of using static operations that return these policies (19b84f0).
  • Adds a static GetJsonNamingPolicyFromEnum function that returns the appropriate JsonNamingPolicy based on a JsonPropertyNamingPolicy (our helper enum) input (0bdf356).
  • Adds a Property Naming Policy input pin of type JsonPropertyNamingPolicy to ObjectToJson. Internally, it sets the PropertyNamingPolicy of the JsonSerializeOption using the aforementioned GetJsonNamingPolicyFromEnum function. (bb8e1f7)

Before change:

Yaagsm6ykJ

After change:

lGGw5odkpb

I have a few issues with the current state of this PR though:

  • I'm not sure if JsonPropertyNamingPolicy is 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.
  • Right now, GetJsonNamingPolicyFromEnum is a static operation living in the XmlNodes class. 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!
  • The default behavior (i.e without explicitly setting a naming policy) was returning a serialized object using PascalCase properties. Unfortunately, JsonNamingPolicy does not allow to pick PascalCase, as you can see on the .NET doc. What if the user actually wants PascalCase then? I was thinking about making the input pin Optional<JsonPropertyNamingPolicy> and only applying SetPropertyNamingPolicy if HasValue returns true, what do you think?
  • I'm adding a .zip file to this PR that shows the change in action. You can open this .vl document with this branch of VL.StandardLibs in your --package-repositories: JsonNamingPolicyPrTest.zip

Related 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

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My change requires a change to the documentation

Will allow to quickly set a naming policy from an enum rather than having to place nodes returning the naming policy
…t an actual JsonNamingPolicy from a JsonPropertyNamingPolicy enum value
Internally uses enum and function from previous commits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant