Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonSerializerOptions.PropertyNamingPolicy not effect ExpandoObject #47707

Closed
ahdung opened this issue Jan 30, 2021 · 5 comments
Closed

JsonSerializerOptions.PropertyNamingPolicy not effect ExpandoObject #47707

ahdung opened this issue Jan 30, 2021 · 5 comments
Labels
area-System.Text.Json question Answer questions and provide assistance, not an issue with source code or documentation.
Milestone

Comments

@ahdung
Copy link

ahdung commented Jan 30, 2021

dynamic foo = new ExpandoObject();
foo.Bar = 3;
JsonSerializer.Serialize(foo, new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
//result: {"Bar":3}
@javiercn javiercn transferred this issue from dotnet/aspnetcore Feb 1, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.Text.Json untriaged New issue has not been triaged by the area owner labels Feb 1, 2021
@ghost
Copy link

ghost commented Feb 1, 2021

Tagging subscribers to this area: @eiriktsarpalis, @layomia
See info in area-owners.md if you want to be subscribed.

Issue Details
dynamic foo = new ExpandoObject();
foo.Bar = 3;
JsonSerializer.Serialize(foo, new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
//result: {"Bar":3}
Author: ahdung
Assignees: -
Labels:

area-System.Text.Json, untriaged

Milestone: -

@eiriktsarpalis
Copy link
Member

I would expect JsonNamingPolicy to only concern matching json property names to .NET member names. ExpandoObject is something different but I can see why users might expect it to have similar behaviour. @layomia is this something we could consider fixing?

@layomia
Copy link
Contributor

layomia commented Feb 1, 2021

This is being addressed along with the work on dynamic - #29690, dotnet/designs#163. I believe the current thinking is to honor this and related options when the feature lands. cc @steveharter.

@eiriktsarpalis
Copy link
Member

Triage:

  • We are working on bringing dynamic support via Support "dynamic" and writable DOM #29690, this will not use ExpandoObject.
  • It might still make sense to add this improvement for ExpandoObject in the future.
  • Need to check: how does Newtonsoft treat ExpandoObject serialization with camelCase settings?

@eiriktsarpalis eiriktsarpalis added this to the Future milestone Feb 3, 2021
@eiriktsarpalis eiriktsarpalis removed the untriaged New issue has not been triaged by the area owner label Feb 3, 2021
@dbc2
Copy link

dbc2 commented Feb 15, 2021

In .NET 5, System.Text.Json serializes ExpandoObject as an IDictionary<string, object> so setting JsonSerializerOptions.DictionaryKeyPolicy = JsonNamingPolicy.CamelCase will cause expandos to be serialized using camel casing.

Demo here: https://dotnetfiddle.net/jf29xe.

@eiriktsarpalis eiriktsarpalis added the question Answer questions and provide assistance, not an issue with source code or documentation. label Oct 21, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Nov 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Text.Json question Answer questions and provide assistance, not an issue with source code or documentation.
Projects
None yet
Development

No branches or pull requests

4 participants