flex-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Greg Dove (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (FLEX-35405) JSON Stringify doesn't work with filters as expected when classes are used as subobjects
Date Fri, 16 Aug 2019 20:39:00 GMT

    [ https://issues.apache.org/jira/browse/FLEX-35405?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16909378#comment-16909378
] 

Greg Dove commented on FLEX-35405:
----------------------------------

This is something that occurs at the native implementation of JSON in the player, not really
Flex as such. So it is (I think) more at the flash player/AVM level.

On the face of it, the issue appears to be the way the native implementation checks for the
presence of fields in the original object being serialized. Perhaps it is attempting to access
the inappropriate fields on the Point instances instead of checking for their presence.

One possibly simple (albeit hacky) option is this:

{{Point.prototype.toJSON = function(k:*):* {}}
{{  //convert Point types to untyped objects for JSON encoding}}
{{  return \{ x: this.x, y: this.y } }}
{{}}}

{{var json:String = JSON.stringify(myObject, ['today', 'obj', 'x', 'y'] );}}

 

 Using a replacer function might be another way to do it, but perhaps could be quite a bit
more work.

> JSON Stringify doesn't work with filters as expected when classes are used as subobjects
> ----------------------------------------------------------------------------------------
>
>                 Key: FLEX-35405
>                 URL: https://issues.apache.org/jira/browse/FLEX-35405
>             Project: Apache Flex
>          Issue Type: Bug
>          Components: .Unspecified - Framework
>    Affects Versions: Apache Flex 4.15.0
>         Environment: Windows 10
>            Reporter: Dan Lambourne
>            Priority: Minor
>
> I have simplified what I was trying to do, but I was trying to follow a JavaScript example
of JSON stringify using filters and in ActionScript I found that the following fails:-
> {{           var myObject:Object = {}}
>  {{                num: 50,}}
>  {{                str: 'A string here',}}
>  {{                today: new Date(),}}
>  {{                ar: ['one', 'two', 'three'],}}
>  {{                obj: [new Point(2,1000),new Point(20,100)]}}
>  \{{            }}}
> {{            var json:String = JSON.stringify(myObject, ['today', 'obj',
'x', 'y'] );}}
> {{Yet changing myObject to the following works:-}}
> {{            var myObject:Object = {}}
>  {{                num: 50,}}
>  {{                str: 'A string here',}}
>  {{                today: new Date(),}}
>  {{                ar: ['one', 'two', 'three'],}}
>  {{                obj: [\{x: 2, y: 1000},\{x: 20,y: 100}]}}
>  \{{            }}}
> It crashes using Point as it says Point doesn't have "today", yet neither does the object
in the working line.



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

Mime
View raw message