JamesRandall / FunctionMonkey

Write more elegant Azure Functions with less boilerplate, more consistency, and support for REST APIs. Docs can be found at https://functionmonkey.azurefromthetrenches.com
MIT License
294 stars 50 forks source link

CamelCaseJsonSerializer does not work for ExpandoObject #150

Open alexeymarkov opened 4 years ago

alexeymarkov commented 4 years ago

Hi, I faced out with a problem returning a JObject as response from HTTP Trigger functions. Json.net ignore any serialization settings when serializing JObject (in my case JObject comes from an abstract "object" type property serialized and then deserialized as "object"). In order to workaround this I decided to deserialize as ExpandoObject but returning it as a response I get again json with PascalCase. The reason is that CamelCaseJsonSerializer constructs CamelCaseNamingStrategy with default parameters but should construct as CamelCasePropertyNamesContractResolver does: new CamelCaseNamingStrategy { ProcessDictionaryKeys = true, OverrideSpecifiedNames = true }

It would be also nice to tweak CamelCaseJsonSerializer and also add a support serialization of JObject e.g. like: var expandoObject = JsonConvert.DeserializeObject(jObject.ToString()); var camelCaseJObject = JObject.FromObject(expandoObject, JsonSerializer);