Don't serialize members with default values

17 views
Skip to first unread message

Chris Broglie

unread,
Nov 18, 2011, 12:33:32 AM11/18/11
to FxWorks
I'd like to propose adding a "defaultValue" property to XmlAttribute
and XmlAttribute which will cause the annotated members to not be
serialized if they have that default value. It was straightforward to
implement myself (thank you for making things so easily customizable),
but I thought it might be useful for others. Here is the example code
for xml elements:

protected override function serializeObject(object:Object,
annotation:XmlMember, parentXml:XML,
serializer:SerializationCore):void {
var shouldSerialize:Boolean = true;
if (!isComplexType(object) &&
(MyXmlElement(annotation).defaultValue != null)) {
var stringValue:String =
serializer.converterStore.objectToString(object, annotation.type);
var defaultValue:String = MyXmlElement(annotation).defaultValue;
if (stringValue == defaultValue) {
shouldSerialize = false;
}
}

if (shouldSerialize) {
super.serializeObject(object, annotation, parentXml, serializer);
}
}

Alexutz

unread,
Nov 18, 2011, 4:39:02 AM11/18/11
to FxWorks
Seems like a good proposal to me. I'll include it in the codbase.

Thanks,
Alex
Reply all
Reply to author
Forward
0 new messages