Serializing ExpandoObject CamelCase Setting

275 views
Skip to first unread message

Patrick Epstein

unread,
Oct 25, 2013, 6:41:52 AM10/25/13
to servic...@googlegroups.com
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

Phillip Haydon

unread,
Nov 19, 2013, 11:41:26 AM11/19/13
to servic...@googlegroups.com
Ah I've run into the same issue. :(

Patrick Epstein

unread,
Nov 19, 2013, 1:18:43 PM11/19/13
to servic...@googlegroups.com
Beware my suggested Code throws a "dont change the dict exception"! 
--
You received this message because you are subscribed to a topic in the Google Groups "ServiceStack .NET Open Source REST Web Services Framework" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/servicestack/6qAPuNZJ-Ck/unsubscribe.
To unsubscribe from this group and all its topics, send an email to servicestack...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


--

http://www.meetbymap.de


Reply all
Reply to author
Forward
0 new messages