You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by jm...@apache.org on 2014/02/24 01:22:03 UTC

git commit: [flex-sdk] [refs/heads/develop] - FLEX-34108 add toJSON to ArrayCollection and ArrayList

Repository: flex-sdk
Updated Branches:
  refs/heads/develop 6942969e4 -> 4cec69c5a


FLEX-34108 add toJSON to ArrayCollection and ArrayList


Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/4cec69c5
Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/4cec69c5
Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/4cec69c5

Branch: refs/heads/develop
Commit: 4cec69c5a6d846c12bd52e08aa2dcdc416b7911d
Parents: 6942969
Author: Justin Mclean <jm...@apache.org>
Authored: Mon Feb 24 11:21:43 2014 +1100
Committer: Justin Mclean <jm...@apache.org>
Committed: Mon Feb 24 11:21:43 2014 +1100

----------------------------------------------------------------------
 .../framework/src/mx/collections/ArrayCollection.as | 16 +++++++++++++++-
 .../framework/src/mx/collections/ArrayList.as       | 14 ++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/4cec69c5/frameworks/projects/framework/src/mx/collections/ArrayCollection.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/framework/src/mx/collections/ArrayCollection.as b/frameworks/projects/framework/src/mx/collections/ArrayCollection.as
index 850317b..9d6f18d 100644
--- a/frameworks/projects/framework/src/mx/collections/ArrayCollection.as
+++ b/frameworks/projects/framework/src/mx/collections/ArrayCollection.as
@@ -105,7 +105,7 @@ public class ArrayCollection extends ListCollectionView implements IExternalizab
     //  Properties
     //
     //--------------------------------------------------------------------------
-
+		
     //----------------------------------
     //  source
     //----------------------------------
@@ -147,6 +147,20 @@ public class ArrayCollection extends ListCollectionView implements IExternalizab
     //
     //--------------------------------------------------------------------------
 
+	/**
+	 *  Converts an Array Collection to JavaScript Object Notation (JSON) format.
+	 *  
+	 *  @langversion 3.0
+	 *  @playerversion Flash 11
+	 *  @playerversion AIR 3.0
+	 *  @productversion Apache Flex 4.12
+	 */
+	public function toJSON(s:String):*
+	{
+		var array:Array = toArray();
+		return JSON.stringify(array);
+	}
+	
     /**
      *  @private
      *  Ensures that only the source property is serialized.

http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/4cec69c5/frameworks/projects/framework/src/mx/collections/ArrayList.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/framework/src/mx/collections/ArrayList.as b/frameworks/projects/framework/src/mx/collections/ArrayList.as
index 1afa845..abdb09b 100644
--- a/frameworks/projects/framework/src/mx/collections/ArrayList.as
+++ b/frameworks/projects/framework/src/mx/collections/ArrayList.as
@@ -271,6 +271,20 @@ public class ArrayList extends EventDispatcher
     // 
     //--------------------------------------------------------------------------
 
+	/**
+	 *  Converts an Array Collection to JavaScript Object Notation (JSON) format.
+	 *  
+	 *  @langversion 3.0
+	 *  @playerversion Flash 11
+	 *  @playerversion AIR 3.0
+	 *  @productversion Apache Flex 4.12
+	 */
+	public function toJSON(s:String):*
+	{
+		var array:Array = toArray();
+		return JSON.stringify(array);
+	}
+	
     /**
      *  Get the item at the specified index.
      * 


RE: git commit: [flex-sdk] [refs/heads/develop] - FLEX-34108 add toJSON to ArrayCollection and ArrayList

Posted by Maurice Amsellem <ma...@systar.com>.
>FWIW, the doc implies there is no JSON class in FP 10.x.  

I don't know for JSON class itself, as I am not using it, but 10.2 includes another JSON-based API:
describeTypeJSON

It's not documented, but used in Parsley (and probably  other software) for fast reflection (much faster that XML based).


Maurice 

-----Message d'origine-----
De : Justin Mclean [mailto:justin@classsoftware.com] 
Envoyé : lundi 24 février 2014 05:58
À : dev@flex.apache.org
Objet : Re: git commit: [flex-sdk] [refs/heads/develop] - FLEX-34108 add toJSON to ArrayCollection and ArrayList

Hi,

> FWIW, the doc implies there is no JSON class in FP 10.x.  Do we care?

Currently we support 10.2 +10.3, I have no idea how people still use that but seem silly to drop support for those for just this feature.

I'll change so it compiles for those but returns nothing.

Thanks,
Justin

Re: git commit: [flex-sdk] [refs/heads/develop] - FLEX-34108 add toJSON to ArrayCollection and ArrayList

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

> FWIW, the doc implies there is no JSON class in FP 10.x.  Do we care?

Currently we support 10.2 +10.3, I have no idea how people still use that but seem silly to drop support for those for just this feature.

I'll change so it compiles for those but returns nothing.

Thanks,
Justin

Re: git commit: [flex-sdk] [refs/heads/develop] - FLEX-34108 add toJSON to ArrayCollection and ArrayList

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

> Does it make sense to you that you didn't get a compile error?
Not really to be honest I would expected "Access of undefined property JSON". 

Perhaps the build script it not picking up the FP version from flex-config.xml (as described in the README)?

Yep confirmed with (in this case I do get an error)
ant -Dplayerglobal.version=10.2

So any reason why it wouldn't be picking it up from flex-config.xml?

Justin

Re: git commit: [flex-sdk] [refs/heads/develop] - FLEX-34108 add toJSON to ArrayCollection and ArrayList

Posted by Erik de Bruin <er...@ixsoftware.nl>.
As to the "worth": what is the cost, really? I mean, it's not really likely
this will be called from a long loop, so that one comparison probably is
"worth it".

I also like how it's self documenting the issue.

EdB




On Mon, Feb 24, 2014 at 9:18 AM, Justin Mclean <ju...@classsoftware.com>wrote:

> Hi,
>
> This works - but is it really worth it?
>
>         public function toJSON(s:String):*
>         {
>                 var array:Array = toArray();
>
>                 if (ApplicationDomain.currentDomain.hasDefinition("JSON"))
>                 {
>                         var json:Class =
> Class(ApplicationDomain.currentDomain.getDefinition("JSON"));
>                         return json["stringify"](array);
>                 }
>                 else
>                 {
>                         return '{"error": "Not supported on Flash Player
> 10"}';
>                 }
>         }
>
> Thanks,
> Justin




-- 
Ix Multimedia Software

Jan Luykenstraat 27
3521 VB Utrecht

T. 06-51952295
I. www.ixsoftware.nl

Re: git commit: [flex-sdk] [refs/heads/develop] - FLEX-34108 add toJSON to ArrayCollection and ArrayList

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

This works - but is it really worth it?

	public function toJSON(s:String):*
	{
		var array:Array = toArray();
		
		if (ApplicationDomain.currentDomain.hasDefinition("JSON"))
		{
			var json:Class = Class(ApplicationDomain.currentDomain.getDefinition("JSON"));
			return json["stringify"](array);
		}
		else
		{
			return '{"error": "Not supported on Flash Player 10"}';
		}
	}

Thanks,
Justin

RE: git commit: [flex-sdk] [refs/heads/develop] - FLEX-34108 add toJSON to ArrayCollection and ArrayList

Posted by Alex Harui <ah...@adobe.com>.
Does it make sense to you that you didn't get a compile error?

Anyway, probably not worth spending too much more time on it.  I really can't imagine any 10.2 users compiling the SDK from source.

-Alex

________________________________________
From: Justin Mclean [justin@classsoftware.com]
Sent: Sunday, February 23, 2014 9:49 PM
To: dev@flex.apache.org
Subject: Re: git commit: [flex-sdk] [refs/heads/develop] - FLEX-34108 add toJSON to ArrayCollection and ArrayList

Hi,

> I'm trying to figure out in my head why you didn't get a compile error when compiling for 10.2.  Did you have a playerglobal from 10.2?
Yep and changed the flex-config.xml file to be 10.2 and swf version 11 and everything - you did get a RTE as described.

Thanks,
Justin

Re: git commit: [flex-sdk] [refs/heads/develop] - FLEX-34108 add toJSON to ArrayCollection and ArrayList

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

> I'm trying to figure out in my head why you didn't get a compile error when compiling for 10.2.  Did you have a playerglobal from 10.2?
Yep and changed the flex-config.xml file to be 10.2 and swf version 11 and everything - you did get a RTE as described.

Thanks,
Justin

RE: git commit: [flex-sdk] [refs/heads/develop] - FLEX-34108 add toJSON to ArrayCollection and ArrayList

Posted by Alex Harui <ah...@adobe.com>.
I'm trying to figure out in my head why you didn't get a compile error when compiling for 10.2.  Did you have a playerglobal from 10.2?

-Alex
________________________________________
From: Justin Mclean [justin@classsoftware.com]
Sent: Sunday, February 23, 2014 9:35 PM
To: dev@flex.apache.org
Subject: Re: git commit: [flex-sdk] [refs/heads/develop] - FLEX-34108 add toJSON to ArrayCollection and ArrayList

Hi,

Turns out no need to change anything to compile under 10.2, but you do get a RTE if you directly call toJSON ("Variable JSON is not defined.") - that's probably OK given that no existing code would be calling it in 10.2 and someone using 10.2 is unlikely to directly call it and the minimum FP version for anything using JSON is likely to be at least 11.1.

Any other opinions?

Thanks,
Justin

Re: git commit: [flex-sdk] [refs/heads/develop] - FLEX-34108 add toJSON to ArrayCollection and ArrayList

Posted by OmPrakash Muppirala <bi...@gmail.com>.
On Sun, Feb 23, 2014 at 9:35 PM, Justin Mclean <ju...@classsoftware.com>wrote:

> Hi,
>
> Turns out no need to change anything to compile under 10.2, but you do get
> a RTE if you directly call toJSON ("Variable JSON is not defined.") -
> that's probably OK given that no existing code would be calling it in 10.2
> and someone using 10.2 is unlikely to directly call it and the minimum FP
> version for anything using JSON is likely to be at least 11.1.
>
> Any other opinions?
>
>
It would be great if we could polyfill JSON serialization in AS3 for older
versions of the Flash Player.  Perhaps we could use code from AS3CoreLib?
[1]
We already use this library in the Installer.

Thanks,
Om

[1]
https://github.com/mikechambers/as3corelib/tree/master/src/com/adobe/serialization/json


> Thanks,
> Justin

Re: git commit: [flex-sdk] [refs/heads/develop] - FLEX-34108 add toJSON to ArrayCollection and ArrayList

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

Turns out no need to change anything to compile under 10.2, but you do get a RTE if you directly call toJSON ("Variable JSON is not defined.") - that's probably OK given that no existing code would be calling it in 10.2 and someone using 10.2 is unlikely to directly call it and the minimum FP version for anything using JSON is likely to be at least 11.1. 

Any other opinions?

Thanks,
Justin

RE: git commit: [flex-sdk] [refs/heads/develop] - FLEX-34108 add toJSON to ArrayCollection and ArrayList

Posted by Alex Harui <ah...@adobe.com>.
FWIW, the doc implies there is no JSON class in FP 10.x.  Do we care?

-Alex
________________________________________
From: jmclean@apache.org [jmclean@apache.org]
Sent: Sunday, February 23, 2014 4:22 PM
To: commits@flex.apache.org
Subject: git commit: [flex-sdk] [refs/heads/develop] - FLEX-34108 add toJSON to ArrayCollection and ArrayList

Repository: flex-sdk
Updated Branches:
  refs/heads/develop 6942969e4 -> 4cec69c5a


FLEX-34108 add toJSON to ArrayCollection and ArrayList


Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/4cec69c5
Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/4cec69c5
Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/4cec69c5

Branch: refs/heads/develop
Commit: 4cec69c5a6d846c12bd52e08aa2dcdc416b7911d
Parents: 6942969
Author: Justin Mclean <jm...@apache.org>
Authored: Mon Feb 24 11:21:43 2014 +1100
Committer: Justin Mclean <jm...@apache.org>
Committed: Mon Feb 24 11:21:43 2014 +1100

----------------------------------------------------------------------
 .../framework/src/mx/collections/ArrayCollection.as | 16 +++++++++++++++-
 .../framework/src/mx/collections/ArrayList.as       | 14 ++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/4cec69c5/frameworks/projects/framework/src/mx/collections/ArrayCollection.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/framework/src/mx/collections/ArrayCollection.as b/frameworks/projects/framework/src/mx/collections/ArrayCollection.as
index 850317b..9d6f18d 100644
--- a/frameworks/projects/framework/src/mx/collections/ArrayCollection.as
+++ b/frameworks/projects/framework/src/mx/collections/ArrayCollection.as
@@ -105,7 +105,7 @@ public class ArrayCollection extends ListCollectionView implements IExternalizab
     //  Properties
     //
     //--------------------------------------------------------------------------
-
+
     //----------------------------------
     //  source
     //----------------------------------
@@ -147,6 +147,20 @@ public class ArrayCollection extends ListCollectionView implements IExternalizab
     //
     //--------------------------------------------------------------------------

+       /**
+        *  Converts an Array Collection to JavaScript Object Notation (JSON) format.
+        *
+        *  @langversion 3.0
+        *  @playerversion Flash 11
+        *  @playerversion AIR 3.0
+        *  @productversion Apache Flex 4.12
+        */
+       public function toJSON(s:String):*
+       {
+               var array:Array = toArray();
+               return JSON.stringify(array);
+       }
+
     /**
      *  @private
      *  Ensures that only the source property is serialized.

http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/4cec69c5/frameworks/projects/framework/src/mx/collections/ArrayList.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/framework/src/mx/collections/ArrayList.as b/frameworks/projects/framework/src/mx/collections/ArrayList.as
index 1afa845..abdb09b 100644
--- a/frameworks/projects/framework/src/mx/collections/ArrayList.as
+++ b/frameworks/projects/framework/src/mx/collections/ArrayList.as
@@ -271,6 +271,20 @@ public class ArrayList extends EventDispatcher
     //
     //--------------------------------------------------------------------------

+       /**
+        *  Converts an Array Collection to JavaScript Object Notation (JSON) format.
+        *
+        *  @langversion 3.0
+        *  @playerversion Flash 11
+        *  @playerversion AIR 3.0
+        *  @productversion Apache Flex 4.12
+        */
+       public function toJSON(s:String):*
+       {
+               var array:Array = toArray();
+               return JSON.stringify(array);
+       }
+
     /**
      *  Get the item at the specified index.
      *