icubilla / jsonexserializer

Automatically exported from code.google.com/p/jsonexserializer
0 stars 0 forks source link

Anonymous types #53

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It seems like Serializer does not work properly with anonymous types.

This code, for example, won't work:

var o = new{ Name="Hello world", Age=10 };
Serializer s = new Serializer( o.GetType() );

Console.WriteLine( s.Serialize( o ) );

It will produce following output:

/*
  Created by JsonExSerializer
  Assembly: CustomHandlerUser, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=
null
  Type: <>f__AnonymousType0`2[[System.String, mscorlib, Version=2.0.0.0,
Culture
=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib,
Version=2.0.
0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]
*/
{
}

Original issue reported on code.google.com by yurafilo...@gmail.com on 25 Dec 2009 at 3:41

GoogleCodeExporter commented 9 years ago
The auto-generated properties aren't generated with setters, so by default the 
serializer ignores them since it couldn't deserialize those properties.  This 
code 
will enable them so the serializer will output them.  

            var o = new { Name = "Hello world", Age = 10 };
            Serializer s = new Serializer(o.GetType());
            TypeData td = s.Config.GetTypeHandler(o.GetType());
            foreach (IPropertyData prop in td.AllProperties)
            {
                prop.Ignored = false;
            }
            Console.WriteLine(s.Serialize(o));

Original comment by elliott....@gmail.com on 28 Dec 2009 at 5:11

GoogleCodeExporter commented 9 years ago
Thanks. It works fine now.
Great tool by the way.

Original comment by yurafilo...@gmail.com on 30 Dec 2009 at 6:35