icubilla / jsonexserializer

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

Include property while Serialize the object #21

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In any class i can exclude the property to deserialize it.

 But i want one of my property in the base calss called "stackTrace" to be 
only added if any error occures. 

so I want a way by which i can by default exclude the property and at 
runtime i can add the property while deserializing it.

Original issue reported on code.google.com by supadhy...@gmail.com on 17 Jul 2008 at 2:49

Attachments:

GoogleCodeExporter commented 9 years ago
In the future please try and use the discussion group for questions:
http://groups.google.com/group/jsonexserializer-discuss

Do you mean serialize or deserialize?  If you want to allow a ignored property 
to be
populated during deserialization set the IgnoredPropertyAction

serializer.Context.IgnoredPropertyAction = IgnoredPropertyOption.SetIfPossible;

If the deserializer encounters an ignored property in the result stream it will 
try
and set it if possible.

You can also programattically ignore a property at runtime:
http://code.google.com/p/jsonexserializer/wiki/IgnoreProperties

Enabling an ignored property is slightly more cumbersome but possible:
TypeHandler handler = serializer.GetTypeHandler(typeof(ChildClass));
foreach (AbstractPropertyHandler propHandler in handler.AllProperties) {
    if (propHandler.Name == "stackTrace")
        propHandler.Ignored = false;
}

Original comment by elliott....@gmail.com on 17 Jul 2008 at 11:47

GoogleCodeExporter commented 9 years ago
Oops, there was a typo in that last bit of code, it should be:
TypeHandler handler = serializer.Context.GetTypeHandler(typeof(ChildClass));

Original comment by elliott....@gmail.com on 18 Jul 2008 at 12:27

GoogleCodeExporter commented 9 years ago

Original comment by elliott....@gmail.com on 19 Jul 2008 at 4:20