Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 53e316aaf450d881c76c24bad8bdc47b2a95d46c 1 parent e1b973c
@darronschall darronschall authored
View
6 src/com/adobe/serialization/json/JSONEncoder.as
@@ -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 ) {
View
8 tests/src/com/adobe/serialization/json/JSONTest.as
@@ -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 );
View
3  tests/src/com/adobe/serialization/json/SimpleClass.as
@@ -70,6 +70,9 @@ package com.adobe.serialization.json
{
return false;
}
+
+ [Transient]
+ public var transientVar:String;
}
Please sign in to comment.
Something went wrong with that request. Please try again.