You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@flex.apache.org by piotrz <pi...@gmail.com> on 2017/04/18 21:29:54 UTC

[FlexJS] Issue with JSON.stringify and Bindable VO objects

Hi All,

It look like we have issue in FlexJS with quite common scenario where
JSON.stringify cannot create json from simple VO object which has been
marked by [Bindable] property.

Description:
I have following class [1], which after compilation has additional
properties:

<http://apache-flex-development.2333347.n4.nabble.com/file/n61195/object_compiled.png> 

In the results JSON.stringify is failing to convert object to a proper JSON
[2], on swf sight there is no problem with such object.

I think creating JSON from object which is marked as [Bindable] will be
quite common cases and need to be resolved.

Two propositions.

Proposition 1:

1) Create our own JSON class with stringify function
2) Create on the compiler sight array called "excluded" which will contains
all additional properties which has been created during compilation
3) In our JSON.stringify use JS version of stringify with second parameter
in following manner [3].

Proposition 2:
1) Same as above
2) Use "accessors" property from FLEXJS_REFLECTION_INFO [4] to determine all
properties from VO
3) Inside our "stringify" function create simple object based on information
from "accessors" and pass that object to JSON.stringify({title: "my title",
page: 5}).

[1] https://paste.apache.org/fuSA
[2] https://paste.apache.org/CyqY
[3] https://paste.apache.org/9GlW
[4] https://paste.apache.org/gpbR

I would be appreciated for feedback and other ideas.

Thanks,
Piotr




-----
Apache Flex PMC
piotrzarzycki21@gmail.com
--
View this message in context: http://apache-flex-development.2333347.n4.nabble.com/FlexJS-Issue-with-JSON-stringify-and-Bindable-VO-objects-tp61195.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.

Re: [FlexJS] Issue with JSON.stringify and Bindable VO objects

Posted by Alex Harui <ah...@adobe.com>.
Hi Piotr,

I am asking you to manually prototype and test that using toJSON will work
before I spend time trying to get the compiler to generate such code.  I
believe it shouldn't take you that long to manually test it.  It will take
quite a while to change the compiler.

Thanks
-Alex



On 4/18/17, 11:23 PM, "piotrz" <pi...@gmail.com> wrote:

>Alex, Harbs,
>
>I understand, but I thought that you will handle those method on the
>compiler sight - Am I miss something ?
>
>Piotr
>
>
>
>-----
>Apache Flex PMC
>piotrzarzycki21@gmail.com
>--
>View this message in context:
>https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapache-fle
>x-development.2333347.n4.nabble.com%2FFlexJS-Issue-with-JSON-stringify-and
>-Bindable-VO-objects-tp61195p61216.html&data=02%7C01%7C%7Cbdc6026905e6430e
>257708d486ee13e7%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636281804490
>300757&sdata=6Oz7wQCVVFgJDUk%2F4FlAMTqXN0B%2FdysQo2qNV37YFlk%3D&reserved=0
>Sent from the Apache Flex Development mailing list archive at Nabble.com.


Re: [FlexJS] Issue with JSON.stringify and Bindable VO objects

Posted by piotrz <pi...@gmail.com>.
Greg,

Ohhh! I know what you mean - bloody deadlines! :) Thank you!

Piotr



-----
Apache Flex PMC
piotrzarzycki21@gmail.com
--
View this message in context: http://apache-flex-development.2333347.n4.nabble.com/FlexJS-Issue-with-JSON-stringify-and-Bindable-VO-objects-tp61195p61368.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.

Re: [FlexJS] Issue with JSON.stringify and Bindable VO objects

Posted by piotrz <pi...@gmail.com>.
Greg,

Thanks for explanation now I understand that it will be transparent for me.

Piotr



-----
Apache Flex PMC
piotrzarzycki21@gmail.com
--
View this message in context: http://apache-flex-development.2333347.n4.nabble.com/FlexJS-Issue-with-JSON-stringify-and-Bindable-VO-objects-tp61195p61279.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.

Re: [FlexJS] Issue with JSON.stringify and Bindable VO objects

Posted by Greg Dove <gr...@gmail.com>.
I will try to look at it this coming weekend. I have some looming deadlines
with work at the moment that could cause me to end up not having much spare
time :)


On Wed, Apr 26, 2017 at 5:13 PM, piotrz <pi...@gmail.com> wrote:

> Hi Greg,
>
> Any chance that you look into that before 0.8 release?
>
> Thanks,
> Piotr
>
>
>
> -----
> Apache Flex PMC
> piotrzarzycki21@gmail.com
> --
> View this message in context: http://apache-flex-
> development.2333347.n4.nabble.com/FlexJS-Issue-with-JSON-
> stringify-and-Bindable-VO-objects-tp61195p61364.html
> Sent from the Apache Flex Development mailing list archive at Nabble.com.
>

Re: [FlexJS] Issue with JSON.stringify and Bindable VO objects

Posted by piotrz <pi...@gmail.com>.
Hi Greg,

Any chance that you look into that before 0.8 release?

Thanks,
Piotr



-----
Apache Flex PMC
piotrzarzycki21@gmail.com
--
View this message in context: http://apache-flex-development.2333347.n4.nabble.com/FlexJS-Issue-with-JSON-stringify-and-Bindable-VO-objects-tp61195p61364.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.

Re: [FlexJS] Issue with JSON.stringify and Bindable VO objects

Posted by piotrz <pi...@gmail.com>.
Greg,

I created jira [1] with as much description as a I can. 

[1] https://issues.apache.org/jira/browse/FLEX-35297

Piotr



-----
Apache Flex PMC
piotrzarzycki21@gmail.com
--
View this message in context: http://apache-flex-development.2333347.n4.nabble.com/FlexJS-Issue-with-JSON-stringify-and-Bindable-VO-objects-tp61195p61248.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.

Re: [FlexJS] Issue with JSON.stringify and Bindable VO objects

Posted by Greg Dove <gr...@gmail.com>.
Yes Piotr, although I think we are all guessing what you want, it will be
helpful to be certain.



On Wed, Apr 19, 2017 at 9:03 PM, piotrz <pi...@gmail.com> wrote:

> Greg,
>
> In order to touch this subject on compiler sight, would it be helpful if I
> prepare what Alex asked me ?
>
> Scenario and generated code in JS sight ?
>
> Piotr
>
>
>
> -----
> Apache Flex PMC
> piotrzarzycki21@gmail.com
> --
> View this message in context: http://apache-flex-
> development.2333347.n4.nabble.com/FlexJS-Issue-with-JSON-
> stringify-and-Bindable-VO-objects-tp61195p61232.html
> Sent from the Apache Flex Development mailing list archive at Nabble.com.
>

Re: [FlexJS] Issue with JSON.stringify and Bindable VO objects

Posted by piotrz <pi...@gmail.com>.
Greg,

In order to touch this subject on compiler sight, would it be helpful if I
prepare what Alex asked me ?

Scenario and generated code in JS sight ?

Piotr



-----
Apache Flex PMC
piotrzarzycki21@gmail.com
--
View this message in context: http://apache-flex-development.2333347.n4.nabble.com/FlexJS-Issue-with-JSON-stringify-and-Bindable-VO-objects-tp61195p61232.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.

Re: [FlexJS] Issue with JSON.stringify and Bindable VO objects

Posted by Greg Dove <gr...@gmail.com>.
Hi Piotr, you should not be concerned about that. For example, your
bindable VO is also IEventDispatcher but you did not code that. The
compiler did it for you after you marked it [Bindable]. So it could also,
for example, add an interface that indicates the class has compiler
generated toJson support if that is helpful to check at runtime. Maybe the
interface is not needed if all you are looking for is the autogenerated
toJson method.

Also my suggestion may not be the best option and I was focusing more on
json to VO than VO to json in that discussion.

-Greg
[sent from my phone]

On 22/04/2017 7:07 PM, "piotrz" <pi...@gmail.com> wrote:

> Hi Greg,
>
> Reading your code we landed again to giving our VO some kind of interface ?
> If yes, that's resolve issue, but it won't be to handy. I don't want to
> implement by my VO any interface - I just wanted to have function toJSON -
> which is recognizable by deserializer default.
>
> var book:Book = new Book();
>
> var str:String = JSON.stringify(book) - inside stringify toJSON is being
> called if exists.
>
> Piotr
>
>
>
> -----
> Apache Flex PMC
> piotrzarzycki21@gmail.com
> --
> View this message in context: http://apache-flex-
> development.2333347.n4.nabble.com/FlexJS-Issue-with-JSON-
> stringify-and-Bindable-VO-objects-tp61195p61277.html
> Sent from the Apache Flex Development mailing list archive at Nabble.com.
>

Re: [FlexJS] Issue with JSON.stringify and Bindable VO objects

Posted by piotrz <pi...@gmail.com>.
Hi Greg,

Reading your code we landed again to giving our VO some kind of interface ?
If yes, that's resolve issue, but it won't be to handy. I don't want to
implement by my VO any interface - I just wanted to have function toJSON -
which is recognizable by deserializer default.

var book:Book = new Book();

var str:String = JSON.stringify(book) - inside stringify toJSON is being
called if exists.

Piotr



-----
Apache Flex PMC
piotrzarzycki21@gmail.com
--
View this message in context: http://apache-flex-development.2333347.n4.nabble.com/FlexJS-Issue-with-JSON-stringify-and-Bindable-VO-objects-tp61195p61277.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.

Re: [FlexJS] Issue with JSON.stringify and Bindable VO objects

Posted by Alex Harui <ah...@adobe.com>.
Hi Greg,

The point wasn't to encourage the use of XML instead of JSON.  It was just
to see if there was any useful mechanisms of retaining type information
and dealing with circularities.

Seems like if we can define how to record the types, that a single Reviver
parameter should be able to effectively do what AMFDecoder does.

Of course, I could be wrong...

-Alex

On 4/21/17, 12:49 PM, "Greg Dove" <gr...@gmail.com> wrote:

>Thanks for that info.
>Most often for client work, I don't choose the data transfer format, and
>tbh I would probably choose json vs. xml if I could choose between the
>two.
>The simplest json based 'typed' data I have seen sends
>"__type":"typename_here" in the generic objects, which can be used during
>deserialization. This is kind of like class alias, but afaik there is no
>official standard for anything like this (I have not searched/checked
>recently).
>
>I think it could be useful to add compiler-generated support into
>metadata-marked classes so that they supported the ability to create
>and/or
>update existing values for values from generic objects, which might
>include
>nested complex types.
>
>something like (pseudo code) (inside ThisClass ):
>
>//support methods
>private static const _permittedFields:Array = ['field1', 'field2'];
>public static function fromObject(object:Object,
>inst:ThisClass=null):ThisClass{
>  if (!inst) inst = new ThisClass();
>   for (var field:String in obj) {
>     //the raw object might have meta data for deserialization or
>unlrelated fields:
>      if(_permittedFields.indexOf(field)==-1) continue;
>      switch (field) {
>        //compiler-generated special-casing of complex type fields:
>        case "complexField" :
>           inst[field] = ComplexFieldType.fromObject(ob
>j[field],inst[field]]);
>         break;
>        default:
>           inst[field] = obj[field]
>       break;
>      }
>   }
> return inst;
>}
>
>public static function toObject
>
>
>//interface methods
>public function updateFrom(obj:Object) :void{
>      fromObject(object,this)
>}
>
>public function getAsObject():Object{
>  //tbd but similar to a reverse version of the above
>}
>
>This type of thing could support both the simple VO case and more complex
>deserialization
>I have done the above sort of thing manually in the past on a few
>occasions
>at least.
>
>I haven't thought too deeply about this (inherited fieldsets need to be
>considered and whether a parent class has the option enabled or not so
>that
>part needs some thought, for example) so maybe there are flaws in the
>above
>idea and perhaps it is more complicated to have the compiler support it
>than I think. But if there is consensus that this type of thing is
>worthwhile, I would be happy to try for this as some sort of opt-in
>compiler support.
>
>
>
>On Fri, Apr 21, 2017 at 3:08 AM, Alex Harui <ah...@adobe.com> wrote:
>
>>
>>
>> On 4/19/17, 1:29 AM, "Greg Dove" <gr...@gmail.com> wrote:
>>
>> >Yes I was thinking more in terms of the times I did this type of thing
>>to
>> >support nested typed objects from raw json, more than simple VOs. Not
>>so
>> >much in terms of using reviver, but going through from json -> generic
>> >object -> typed object with most of the support for the last part
>>being in
>> >the abstract base class, and extra field mappings to complex field
>>types
>> >defined in subclasses for specific fields. It was maintainable at the
>> >individual class level, but still quite complicated. Poor man's amf.
>> >
>> >Probably not relevant here for simple VOs.
>>
>> Did you look at the AMFX classes (not regular AMF)?  It might serve as a
>> starting point for a JSON version.
>>
>> [1]
>> 
>>https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbooks.go
>>ogle.com%2Fbooks%3Fid%3DqtlUSkC4HRQC%26pg%3DPT1458%26lpg&data=02%7C01%7C%
>>7C424b478160694d23ad5e08d488ef801e%7Cfa7b1b5a7b34438794aed2c178decee1%7C0
>>%7C0%7C636284009615781999&sdata=PVOZOI7ESKVIOErEPvYqs%2BX3%2BiBAR0Rqzm%2B
>>Y%2F0P5LKE%3D&reserved=0
>> =PT1458&dq=AMFX
>> +specification+adobe&source=bl&ots=1Hx1n3jo0d&sig=puxfHwWuDS
>> kP-jwbXVKGFmriy
>> 64&hl=en&sa=X&ved=0ahUKEwipx8fAp7PTAhXpsVQKHSL1Cf4Q6AEIRjAH#
>> v=onepage&q=AMF
>> X%20specification%20adobe&f=false
>> 
>><https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbooks.g
>>oogle.com%2Fbooks%3Fid%3DqtlUSkC4HRQC%26pg%3DPT1458%26lpg%3DPT1458%26dq%3
>>DAMFX%2Bspecification%2Badobe%26source%3Dbl%26ots%3D1Hx1n3jo0d%26sig%3Dpu
>>xfHwWuDSkP-jwbXVKGFmriy64%26hl%3Den%26sa%3DX%26ved%3D0ahUKEwipx8fAp7PTAhX
>>psVQKHSL1Cf4Q6AEIRjAH%23v%3Donepage%26q%3DAMFX%2520specification%2520adob
>>e%26f%3Dfalse&data=02%7C01%7C%7C424b478160694d23ad5e08d488ef801e%7Cfa7b1b
>>5a7b34438794aed2c178decee1%7C0%7C0%7C636284009615781999&sdata=4Q%2BIM%2FN
>>Rd%2B3WdeQyL%2BAgmYdMKg6aTAJ70wzZk1wrxps%3D&reserved=0>
>>
>> -Alex
>>
>>


Re: [FlexJS] Issue with JSON.stringify and Bindable VO objects

Posted by Greg Dove <gr...@gmail.com>.
Thanks for that info.
Most often for client work, I don't choose the data transfer format, and
tbh I would probably choose json vs. xml if I could choose between the two.
The simplest json based 'typed' data I have seen sends
"__type":"typename_here" in the generic objects, which can be used during
deserialization. This is kind of like class alias, but afaik there is no
official standard for anything like this (I have not searched/checked
recently).

I think it could be useful to add compiler-generated support into
metadata-marked classes so that they supported the ability to create and/or
update existing values for values from generic objects, which might include
nested complex types.

something like (pseudo code) (inside ThisClass ):

//support methods
private static const _permittedFields:Array = ['field1', 'field2'];
public static function fromObject(object:Object,
inst:ThisClass=null):ThisClass{
  if (!inst) inst = new ThisClass();
   for (var field:String in obj) {
     //the raw object might have meta data for deserialization or
unlrelated fields:
      if(_permittedFields.indexOf(field)==-1) continue;
      switch (field) {
        //compiler-generated special-casing of complex type fields:
        case "complexField" :
           inst[field] = ComplexFieldType.fromObject(ob
j[field],inst[field]]);
         break;
        default:
           inst[field] = obj[field]
       break;
      }
   }
 return inst;
}

public static function toObject


//interface methods
public function updateFrom(obj:Object) :void{
      fromObject(object,this)
}

public function getAsObject():Object{
  //tbd but similar to a reverse version of the above
}

This type of thing could support both the simple VO case and more complex
deserialization
I have done the above sort of thing manually in the past on a few occasions
at least.

I haven't thought too deeply about this (inherited fieldsets need to be
considered and whether a parent class has the option enabled or not so that
part needs some thought, for example) so maybe there are flaws in the above
idea and perhaps it is more complicated to have the compiler support it
than I think. But if there is consensus that this type of thing is
worthwhile, I would be happy to try for this as some sort of opt-in
compiler support.



On Fri, Apr 21, 2017 at 3:08 AM, Alex Harui <ah...@adobe.com> wrote:

>
>
> On 4/19/17, 1:29 AM, "Greg Dove" <gr...@gmail.com> wrote:
>
> >Yes I was thinking more in terms of the times I did this type of thing to
> >support nested typed objects from raw json, more than simple VOs. Not so
> >much in terms of using reviver, but going through from json -> generic
> >object -> typed object with most of the support for the last part being in
> >the abstract base class, and extra field mappings to complex field types
> >defined in subclasses for specific fields. It was maintainable at the
> >individual class level, but still quite complicated. Poor man's amf.
> >
> >Probably not relevant here for simple VOs.
>
> Did you look at the AMFX classes (not regular AMF)?  It might serve as a
> starting point for a JSON version.
>
> [1]
> https://books.google.com/books?id=qtlUSkC4HRQC&pg=PT1458&lpg
> =PT1458&dq=AMFX
> +specification+adobe&source=bl&ots=1Hx1n3jo0d&sig=puxfHwWuDS
> kP-jwbXVKGFmriy
> 64&hl=en&sa=X&ved=0ahUKEwipx8fAp7PTAhXpsVQKHSL1Cf4Q6AEIRjAH#
> v=onepage&q=AMF
> X%20specification%20adobe&f=false
> <https://books.google.com/books?id=qtlUSkC4HRQC&pg=PT1458&lpg=PT1458&dq=AMFX+specification+adobe&source=bl&ots=1Hx1n3jo0d&sig=puxfHwWuDSkP-jwbXVKGFmriy64&hl=en&sa=X&ved=0ahUKEwipx8fAp7PTAhXpsVQKHSL1Cf4Q6AEIRjAH#v=onepage&q=AMFX%20specification%20adobe&f=false>
>
> -Alex
>
>

Re: [FlexJS] Issue with JSON.stringify and Bindable VO objects

Posted by Alex Harui <ah...@adobe.com>.

On 4/19/17, 1:29 AM, "Greg Dove" <gr...@gmail.com> wrote:

>Yes I was thinking more in terms of the times I did this type of thing to
>support nested typed objects from raw json, more than simple VOs. Not so
>much in terms of using reviver, but going through from json -> generic
>object -> typed object with most of the support for the last part being in
>the abstract base class, and extra field mappings to complex field types
>defined in subclasses for specific fields. It was maintainable at the
>individual class level, but still quite complicated. Poor man's amf.
>
>Probably not relevant here for simple VOs.

Did you look at the AMFX classes (not regular AMF)?  It might serve as a
starting point for a JSON version.

[1] 
https://books.google.com/books?id=qtlUSkC4HRQC&pg=PT1458&lpg=PT1458&dq=AMFX
+specification+adobe&source=bl&ots=1Hx1n3jo0d&sig=puxfHwWuDSkP-jwbXVKGFmriy
64&hl=en&sa=X&ved=0ahUKEwipx8fAp7PTAhXpsVQKHSL1Cf4Q6AEIRjAH#v=onepage&q=AMF
X%20specification%20adobe&f=false

-Alex


Re: [FlexJS] Issue with JSON.stringify and Bindable VO objects

Posted by Greg Dove <gr...@gmail.com>.
Yes I was thinking more in terms of the times I did this type of thing to
support nested typed objects from raw json, more than simple VOs. Not so
much in terms of using reviver, but going through from json -> generic
object -> typed object with most of the support for the last part being in
the abstract base class, and extra field mappings to complex field types
defined in subclasses for specific fields. It was maintainable at the
individual class level, but still quite complicated. Poor man's amf.

Probably not relevant here for simple VOs.




On Wed, Apr 19, 2017 at 6:47 PM, Alex Harui <ah...@adobe.com> wrote:

>
>
> On 4/18/17, 11:45 PM, "Greg Dove" <gr...@gmail.com> wrote:
>
> >maybe fromJson is not the best example :)
>
> I'm not sure I understand what you want to do.  Are you trying to support
> types in the JSON reviver?
>
> -Alex
>
> >
> >
> >On Wed, Apr 19, 2017 at 6:42 PM, Greg Dove <gr...@gmail.com> wrote:
> >
> >> I'd be happy to look at compiler side support for this at some point
> >> during the next month, it is something I have hand-coded many times and
> >>I
> >> think to/from JSON style support would be helpful for VO, especially
> >> bindables. It would need to add an interface I think so you could cast
> >>the
> >> VO in serialize/deserialize parts of service calls etc.
> >>
> >> e.g. creating VO from json:
> >>
> >> var myVO:VOClass = new VOClass()
> >> (myVO as IJSONable).fromJSON(jsonData)
> >>
> >> I know not everyone likes metadata, but this seems like a VO-specific
> >> metadata on the class, that the compiler would pick up on. It could even
> >> ignore [Transient] members if there are any.
> >>
> >> This keeps it away from being dependent on the reflection data and makes
> >> it specific to the classes that need it
> >>
> >>
> >>
> >>
> >> On Wed, Apr 19, 2017 at 6:23 PM, piotrz <pi...@gmail.com>
> >>wrote:
> >>
> >>> Alex, Harbs,
> >>>
> >>> I understand, but I thought that you will handle those method on the
> >>> compiler sight - Am I miss something ?
> >>>
> >>> Piotr
> >>>
> >>>
> >>>
> >>> -----
> >>> Apache Flex PMC
> >>> piotrzarzycki21@gmail.com
> >>> --
> >>> View this message in context: http://apache-flex-development
> >>> .2333347.n4.nabble.com/FlexJS-Issue-with-JSON-stringify-and-
> >>> Bindable-VO-objects-tp61195p61216.html
> >>> Sent from the Apache Flex Development mailing list archive at
> >>>Nabble.com.
> >>>
> >>
> >>
>
>

Re: [FlexJS] Issue with JSON.stringify and Bindable VO objects

Posted by Alex Harui <ah...@adobe.com>.

On 4/18/17, 11:45 PM, "Greg Dove" <gr...@gmail.com> wrote:

>maybe fromJson is not the best example :)

I'm not sure I understand what you want to do.  Are you trying to support
types in the JSON reviver?

-Alex

>
>
>On Wed, Apr 19, 2017 at 6:42 PM, Greg Dove <gr...@gmail.com> wrote:
>
>> I'd be happy to look at compiler side support for this at some point
>> during the next month, it is something I have hand-coded many times and
>>I
>> think to/from JSON style support would be helpful for VO, especially
>> bindables. It would need to add an interface I think so you could cast
>>the
>> VO in serialize/deserialize parts of service calls etc.
>>
>> e.g. creating VO from json:
>>
>> var myVO:VOClass = new VOClass()
>> (myVO as IJSONable).fromJSON(jsonData)
>>
>> I know not everyone likes metadata, but this seems like a VO-specific
>> metadata on the class, that the compiler would pick up on. It could even
>> ignore [Transient] members if there are any.
>>
>> This keeps it away from being dependent on the reflection data and makes
>> it specific to the classes that need it
>>
>>
>>
>>
>> On Wed, Apr 19, 2017 at 6:23 PM, piotrz <pi...@gmail.com>
>>wrote:
>>
>>> Alex, Harbs,
>>>
>>> I understand, but I thought that you will handle those method on the
>>> compiler sight - Am I miss something ?
>>>
>>> Piotr
>>>
>>>
>>>
>>> -----
>>> Apache Flex PMC
>>> piotrzarzycki21@gmail.com
>>> --
>>> View this message in context: http://apache-flex-development
>>> .2333347.n4.nabble.com/FlexJS-Issue-with-JSON-stringify-and-
>>> Bindable-VO-objects-tp61195p61216.html
>>> Sent from the Apache Flex Development mailing list archive at
>>>Nabble.com.
>>>
>>
>>


Re: [FlexJS] Issue with JSON.stringify and Bindable VO objects

Posted by Greg Dove <gr...@gmail.com>.
maybe fromJson is not the best example :)


On Wed, Apr 19, 2017 at 6:42 PM, Greg Dove <gr...@gmail.com> wrote:

> I'd be happy to look at compiler side support for this at some point
> during the next month, it is something I have hand-coded many times and I
> think to/from JSON style support would be helpful for VO, especially
> bindables. It would need to add an interface I think so you could cast the
> VO in serialize/deserialize parts of service calls etc.
>
> e.g. creating VO from json:
>
> var myVO:VOClass = new VOClass()
> (myVO as IJSONable).fromJSON(jsonData)
>
> I know not everyone likes metadata, but this seems like a VO-specific
> metadata on the class, that the compiler would pick up on. It could even
> ignore [Transient] members if there are any.
>
> This keeps it away from being dependent on the reflection data and makes
> it specific to the classes that need it
>
>
>
>
> On Wed, Apr 19, 2017 at 6:23 PM, piotrz <pi...@gmail.com> wrote:
>
>> Alex, Harbs,
>>
>> I understand, but I thought that you will handle those method on the
>> compiler sight - Am I miss something ?
>>
>> Piotr
>>
>>
>>
>> -----
>> Apache Flex PMC
>> piotrzarzycki21@gmail.com
>> --
>> View this message in context: http://apache-flex-development
>> .2333347.n4.nabble.com/FlexJS-Issue-with-JSON-stringify-and-
>> Bindable-VO-objects-tp61195p61216.html
>> Sent from the Apache Flex Development mailing list archive at Nabble.com.
>>
>
>

Re: [FlexJS] Issue with JSON.stringify and Bindable VO objects

Posted by piotrz <pi...@gmail.com>.
Ohh! I got you :) I will prepare something and post here. 

Thank you!



-----
Apache Flex PMC
piotrzarzycki21@gmail.com
--
View this message in context: http://apache-flex-development.2333347.n4.nabble.com/FlexJS-Issue-with-JSON-stringify-and-Bindable-VO-objects-tp61195p61228.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.

Re: [FlexJS] Issue with JSON.stringify and Bindable VO objects

Posted by Alex Harui <ah...@adobe.com>.

On 4/18/17, 11:40 PM, "piotrz" <pi...@gmail.com> wrote:

>Greg,
>
>The deal is that I don't want to any interface. In pure Flex we don't need
>interface and stringify is working. It would be awesome if you could take
>a
>look into that.
>
>Alex,
>
>So I don't understand what do you want from me. Do you want me to manually
>create toJSON inside object and implement logic which return pure Object ?

Yes.  Imagine you are the compiler.  What code can you add to your value
objects that will make it work?  Once we know what code is needed to make
it work, we can try to get the compiler to generate that code.

I'm stopping work for tonight so hopefully you can make progress.

Thanks,
-Alex


Re: [FlexJS] Issue with JSON.stringify and Bindable VO objects

Posted by piotrz <pi...@gmail.com>.
Greg,

The deal is that I don't want to any interface. In pure Flex we don't need
interface and stringify is working. It would be awesome if you could take a
look into that.

Alex,

So I don't understand what do you want from me. Do you want me to manually
create toJSON inside object and implement logic which return pure Object ?

Piotr



-----
Apache Flex PMC
piotrzarzycki21@gmail.com
--
View this message in context: http://apache-flex-development.2333347.n4.nabble.com/FlexJS-Issue-with-JSON-stringify-and-Bindable-VO-objects-tp61195p61223.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.

Re: [FlexJS] Issue with JSON.stringify and Bindable VO objects

Posted by Greg Dove <gr...@gmail.com>.
I'd be happy to look at compiler side support for this at some point during
the next month, it is something I have hand-coded many times and I think
to/from JSON style support would be helpful for VO, especially bindables.
It would need to add an interface I think so you could cast the VO in
serialize/deserialize parts of service calls etc.

e.g. creating VO from json:

var myVO:VOClass = new VOClass()
(myVO as IJSONable).fromJSON(jsonData)

I know not everyone likes metadata, but this seems like a VO-specific
metadata on the class, that the compiler would pick up on. It could even
ignore [Transient] members if there are any.

This keeps it away from being dependent on the reflection data and makes it
specific to the classes that need it




On Wed, Apr 19, 2017 at 6:23 PM, piotrz <pi...@gmail.com> wrote:

> Alex, Harbs,
>
> I understand, but I thought that you will handle those method on the
> compiler sight - Am I miss something ?
>
> Piotr
>
>
>
> -----
> Apache Flex PMC
> piotrzarzycki21@gmail.com
> --
> View this message in context: http://apache-flex-
> development.2333347.n4.nabble.com/FlexJS-Issue-with-JSON-
> stringify-and-Bindable-VO-objects-tp61195p61216.html
> Sent from the Apache Flex Development mailing list archive at Nabble.com.
>

Re: [FlexJS] Issue with JSON.stringify and Bindable VO objects

Posted by piotrz <pi...@gmail.com>.
Alex, Harbs,

I understand, but I thought that you will handle those method on the
compiler sight - Am I miss something ?

Piotr



-----
Apache Flex PMC
piotrzarzycki21@gmail.com
--
View this message in context: http://apache-flex-development.2333347.n4.nabble.com/FlexJS-Issue-with-JSON-stringify-and-Bindable-VO-objects-tp61195p61216.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.

Re: [FlexJS] Issue with JSON.stringify and Bindable VO objects

Posted by Alex Harui <ah...@adobe.com>.
On 4/18/17, 11:20 PM, "Harbs" <ha...@gmail.com> wrote:

>That seems to make sense to me.
>
>toJSON is something which needs to be defined. If it’s not defined, it’s
>not going to work...

That's my understanding as well.  The ValueObject class will need to
define a toJSON method.  I don't think there is a default.

-Alex


Re: [FlexJS] Issue with JSON.stringify and Bindable VO objects

Posted by Harbs <ha...@gmail.com>.
That seems to make sense to me.

toJSON is something which needs to be defined. If it’s not defined, it’s not going to work...

Am I missing something?

> On Apr 19, 2017, at 1:57 AM, piotrz <pi...@gmail.com> wrote:
> 
> Alex,
> 
> Just tested on SWF sight and got this one:
> <http://apache-flex-development.2333347.n4.nabble.com/file/n61213/to_json_swf.png> 
> 
> In JS stack trace is:
> <http://apache-flex-development.2333347.n4.nabble.com/file/n61213/to_json_js.png> 
> 
> If we can still to do something with this I will raise a jir - let me know.
> 
> Piotr
> 
> 
> 
> 
> 
> -----
> Apache Flex PMC
> piotrzarzycki21@gmail.com
> --
> View this message in context: http://apache-flex-development.2333347.n4.nabble.com/FlexJS-Issue-with-JSON-stringify-and-Bindable-VO-objects-tp61195p61213.html
> Sent from the Apache Flex Development mailing list archive at Nabble.com.


Re: [FlexJS] Issue with JSON.stringify and Bindable VO objects

Posted by piotrz <pi...@gmail.com>.
Alex,

Just tested on SWF sight and got this one:
<http://apache-flex-development.2333347.n4.nabble.com/file/n61213/to_json_swf.png> 

In JS stack trace is:
<http://apache-flex-development.2333347.n4.nabble.com/file/n61213/to_json_js.png> 

If we can still to do something with this I will raise a jir - let me know.

Piotr





-----
Apache Flex PMC
piotrzarzycki21@gmail.com
--
View this message in context: http://apache-flex-development.2333347.n4.nabble.com/FlexJS-Issue-with-JSON-stringify-and-Bindable-VO-objects-tp61195p61213.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.

Re: [FlexJS] Issue with JSON.stringify and Bindable VO objects

Posted by Alex Harui <ah...@adobe.com>.

On 4/18/17, 10:34 PM, "piotrz" <pi...@gmail.com> wrote:

>Hi Alex,
>
>I just tried toJSON method on object in JS and it failed with error that
>those method do not exist. Did you mean something like this ?
>
> var book:Book = new Book();
>book.title = "Trump";
>
>var toJSON:Object = book["toJSON"]();
>var jsonString:String = JSON.stringify(toJSON);
>
>If such function do not exist we can still do something with this ?

Yes, we can probably make this work.  Does this work for SWF as well?

Thanks,
-Alex


Re: [FlexJS] Issue with JSON.stringify and Bindable VO objects

Posted by piotrz <pi...@gmail.com>.
Hi Alex,

I just tried toJSON method on object in JS and it failed with error that
those method do not exist. Did you mean something like this ? 

 var book:Book = new Book();
book.title = "Trump";

var toJSON:Object = book["toJSON"]();
var jsonString:String = JSON.stringify(toJSON);

If such function do not exist we can still do something with this ?

Thanks,
Piotr





-----
Apache Flex PMC
piotrzarzycki21@gmail.com
--
View this message in context: http://apache-flex-development.2333347.n4.nabble.com/FlexJS-Issue-with-JSON-stringify-and-Bindable-VO-objects-tp61195p61208.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.