-
Notifications
You must be signed in to change notification settings - Fork 10k
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
Dynamic property in typed object not serialized to camelCase JSON #9543
Comments
You likely need to set ProcessDictionaryKeys to true on the CamelCaseNamingStrategy. Something like new DefaultContractResolver()
{
NamingStrategy = new CamelCaseNamingStrategy()
{
ProcessDictionaryKeys = true
}
}; cc @JamesNK |
I tried this as well, but it didn't bring any solution, the situation is the same, with one minor difference that, when setting the contractresolver to a defaultcontractresolver with above settings, any property that has a JsonProperty annotation, is serialized according to that jsonproperty annotation, what we don't want either. Thanks for the suggestion, any other ideas? |
Is your dynamic property a JObject? A JObject's JSON is not changed by a naming strategy, it is serialized as is. |
No, basically our dynamic object is an event class. So the flow is like this:
API Call:
At the moment the API call is being done, and the data is being fetched, there's no track anymore of the original event object's type (A), so perhaps that's the issue here, and this is causing it to be handled as a JObject? I don't see a way around this though :/ |
I'm confused, is it a JObject or not? A JObject will not be effected by a naming standard. It is written as is because as far as the serializer is concerned it is already JSON. |
I have the same problem.
Output: {"p1":"Test","someDymamic":{"Property":"test"}} when returned from the controller i would expect the above to follow the settings provided in the DefaultContractResolver (in my case camel case), except it defaults to pascal case. Currently you would get a mix of casing returned. The view model will follow Camel Case, but the dynamic property would not. ** Update |
Thank you for contacting us. Due to no activity on this issue we're closing it in an effort to keep our backlog clean. If you believe there is a concern related to the ASP.NET Core framework, which hasn't been addressed yet, please file a new issue. |
Describe the bug
When calling an API that returns a typed object that holds a dynamic property, the properties of the typed object are (correctly) returned as camelCase, while the dynamic property properties are in (Upper)PascalCase.
Setting the default JsonSerializer ContractResolver to CamelCase does not seem to work.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Properties of dynamic objects should follow the configured JSON Contract Resolver settings.
The text was updated successfully, but these errors were encountered: