Hi,
I need to serialize an object with an ExpandoObject property. I expected the properties of the expando obj also to be CamelCase with the settings below, but they are not.
var foo = new Foobar
{
Name = "I'm CamelCase",
Data = new ExpandoObject(),
Anonymous = new { Bar = "me too" }
};
// expando
foo.Data.Bar = "I'm not CamelCase";
// setup
JsConfig.ExcludeTypeInfo = true;
JsConfig.EmitCamelCaseNames = true;
result :
{"name":"I'm CamelCase","data":{"Bar":"I'm not"},"anonymous":{"bar":"me 2"}}
My solution so far is manipulating the ExpandoObject before serializing:
JsConfig<ExpandoObject>.OnSerializingFn = (a) =>
{
var dict = a as IDictionary<string, object>;
foreach (var key in dict.Keys)
{
object value = dict[key];
dict.Remove( key );
dict.Add( key.ToCamelCase(), value );
}
return (dynamic)dict;
};
Should I do that or should the serialization be changed in general for ExpandoObject properties?
Thanks!
Patrick