tl24 / jsonexserializer

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

Allow a way to omit properties that are null or have default value #23

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
As a way of compressing the output, allow a way to omit any properties that
are empty, null, or have the default value.

Since the concept of what is the "default value" is instance specific, the
user probably needs to be able to specify what the default is.

Something similar to:

[JsonExProperty(OmitDefaults=true, DefaultValue="")]
public string StringProperty {
  get { return _s; }
  set { _s = value; }
}

[JsonExProperty(OmitDefaults=true, DefaultValue=3.14)]
public double Pi {
  get { return _p; }
  set { _p = value; }
}

Should probably be a way to turn this on at the class level and globally.

Original issue reported on code.google.com by elliott....@gmail.com on 23 Jul 2008 at 1:02

GoogleCodeExporter commented 9 years ago
At the class level might look like this:
[JsonExOmitDefaults]
public class MyClass {
...
The default value would just be the framework default for the class unless the 
user
overrides it with maybe special handling for string also check for empty string.

To set globally:
serializer.Context.OmitDefaults = true;
This property would be off by default.  Not sure how useful the global property 
would
be, since its a little dangerous.

Original comment by elliott....@gmail.com on 23 Jul 2008 at 1:08

GoogleCodeExporter commented 9 years ago

Original comment by elliott....@gmail.com on 2 Jul 2009 at 12:22

GoogleCodeExporter commented 9 years ago
Release 3.1

Original comment by elliott....@gmail.com on 16 Apr 2010 at 3:51