Permalink
Browse files

Fixes issue #110 - [Transient] metadata is now respected by the encoder.

  • Loading branch information...
1 parent e1b973c commit 53e316aaf450d881c76c24bad8bdc47b2a95d46c @darronschall darronschall committed Jul 8, 2009
@@ -277,6 +277,12 @@ package com.adobe.serialization.json
// serialize them along with their values.
for each ( var v:XML in classInfo..*.( name() == "variable" || name() == "accessor" ) )
{
+ // Issue #110 - If [Transient] metadata exists, then we should skip the var
+ if ( v.metadata && v.metadata.( @name == "Transient" ).length() > 0 )
+ {
+ continue;
+ }
+
// When the length is 0 we're adding the first item so
// no comma is necessary
if ( s.length > 0 ) {
@@ -457,9 +457,14 @@ package com.adobe.serialization.json
public function testEncodeClassInstance():void
{
- var s:String = JSON.encode( new SimpleClass() );
+ var customObject:SimpleClass = new SimpleClass();
+ customObject.transientVar = "Should not be encoded";
+
+ var s:String = JSON.encode( customObject );
assertTrue( "Has length", s.length > 0 );
+ // Make sure the transient variable was not encoded
+ assertEquals( "Should not find transient var in string", -1, s.indexOf( "\"transientVar\":\"Should not be encoded\"" ) );
// Decode the string so we can verify that it has the properties
var o:Object = JSON.decode( s );
@@ -469,6 +474,7 @@ package com.adobe.serialization.json
assertNotNull( o.publicVar2 );
assertNotNull( o.accessor1 );
assertNotNull( o.accessor2 );
+ assertNull( o.transientVar );
assertEquals( 17, o.publicVar1 );
assertEquals( 20, o.publicVar2 );
assertEquals( 25, o.accessor1 );
@@ -70,6 +70,9 @@ package com.adobe.serialization.json
{
return false;
}
+
+ [Transient]
+ public var transientVar:String;
}

0 comments on commit 53e316a

Please sign in to comment.