You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by PKumar <pr...@gmail.com> on 2016/11/12 16:27:37 UTC

FlexJS : AMFJS Class Mapping

Hi,

I am working on amfjs integration and it almost done. but i need to map the
java clas object to AS3 class object. I am getting the _explicitType from
BlazeDS side but could not map it with AS3 object. i also used the
registerClassAlias but nothing working. I attached the trace from chorme. 
Please suggest how can i do it in FlexJS.

<http://apache-flex-users.2333346.n4.nabble.com/file/n14106/capture.png> 



-----
Regards,
Prashant
--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/FlexJS-AMFJS-Class-Mapping-tp14106.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: FlexJS : AMFJS Class Mapping

Posted by PKumar <pr...@gmail.com>.
Thanks for providing the code, i will try it.



-----
Regards,
Prashant
--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/FlexJS-AMFJS-Class-Mapping-tp14106p14118.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: FlexJS : AMFJS Class Mapping

Posted by Greg Dove <gr...@gmail.com>.
What I am suggesting is to try something like this (I have not *actually*
tried this, just typed it up quickly):


var patientList:ArrayList = new ArrayList(evt.data as Array);
typeUntypedItems(patientList);
trace("list=" + patientList);



    private function typeUntypedItems(items:ArrayList):void{
        if (!items) return;
        var l:uint = items.length;
        var i:uint;
        for (i=0;i<l;i++) {
            var obj:Object = items.getItemAt(i);
            if (obj.hasOwnProperty("_explicitType")) {
                try {
                    var classToInstantiate:Class =
getClassByAlias(obj._explicitType);
                    var typedInstance:Object = new classToInstantiate();
                    for (var field:String in obj) {
                        if (field=="_explicitType") continue;
                        typedInstance[field] = obj[field];
                    }
                   //swap in the typed object
                    items.setItemAt(typedInstance,i);
                }  catch(e:Error) {}
            }
        }
    }


As I said earlier, it would be much better if the amf deserializer code
could take some sort of plugin or configuration so that it could do the
instantiation of the typed objects itself directly instead of creating the
untyped object in the first place. Also the above approach would only work
for simple value objects with string or numeric values and does not perform
nested typing. It's possible of course to add that support by checking each
field, but again this would be best done in the original deserialization
code to avoid 'double handling'.






On Mon, Nov 14, 2016 at 6:41 AM, PKumar <pr...@gmail.com> wrote:

> Thanks for details, below is my code,
>
> //Patient is AS3 class and i am  trying to map it with
> org.blazeds.vo.Patient, which is java class.
> *registerClassAlias("org.blazeds.vo.Patient",Patient);*
>
> I am getting the list of Patient from BlazeDs side and trying to use it
> like
> below,
>
> trace("Result=" + evt.data);
> var patientList:ArrayList = new ArrayList(evt.data as Array);
> trace("list=" + patientList);
> var patient:Patient = patientList.getItemIndex(0) as Patient;
> trace("Patient=" + patient); // Patient is null here
>
>
>
>
> -----
> Regards,
> Prashant
> --
> View this message in context: http://apache-flex-users.
> 2333346.n4.nabble.com/FlexJS-AMFJS-Class-Mapping-tp14106p14112.html
> Sent from the Apache Flex Users mailing list archive at Nabble.com.
>

Re: FlexJS : AMFJS Class Mapping

Posted by PKumar <pr...@gmail.com>.
Thanks for details, below is my code, 

//Patient is AS3 class and i am  trying to map it with 
org.blazeds.vo.Patient, which is java class.
*registerClassAlias("org.blazeds.vo.Patient",Patient);*

I am getting the list of Patient from BlazeDs side and trying to use it like
below,

trace("Result=" + evt.data);
var patientList:ArrayList = new ArrayList(evt.data as Array);
trace("list=" + patientList);
var patient:Patient = patientList.getItemIndex(0) as Patient;
trace("Patient=" + patient); // Patient is null here




-----
Regards,
Prashant
--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/FlexJS-AMFJS-Class-Mapping-tp14106p14112.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: FlexJS : AMFJS Class Mapping

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

On 11/12/16, 2:03 PM, "Greg Dove" <gr...@gmail.com> wrote:

>Hi Prashant,
>
>The methods added to the reflection package were to support storing
>aliases
>(for class mappings) and also retrieving the class based on the stored
>alias.
>
>In the patient case the local alias would also be "org.blazeds.vo.Patient"
>
>I am not familiar with the approach you are using for deserializing the
>amf
>in js, but I expect the general approach should be something like this:
>
>a) identify the alias from the inbound amf data (seems like the
>_explicitType field in your data)
>b) retrieve the local class that corresponds to that alias and instantiate
>an instance using getClassByAlias method from the _explicitType value:
>var
>classToInstantiate:Class = getClassByAlias("org.blazeds.vo.Patient");
>This class should have been already registered using registerClassAlias at
>some earlier point in time.

I think the cross-compiler isn't generating the registerClassAlias.  File
a bug and we'll get to it.

-Alex


Re: FlexJS : AMFJS Class Mapping

Posted by Greg Dove <gr...@gmail.com>.
Hi Prashant,

The methods added to the reflection package were to support storing aliases
(for class mappings) and also retrieving the class based on the stored
alias.

In the patient case the local alias would also be "org.blazeds.vo.Patient"

I am not familiar with the approach you are using for deserializing the amf
in js, but I expect the general approach should be something like this:

a) identify the alias from the inbound amf data (seems like the
_explicitType field in your data)
b) retrieve the local class that corresponds to that alias and instantiate
an instance using getClassByAlias method from the _explicitType value:  var
classToInstantiate:Class = getClassByAlias("org.blazeds.vo.Patient");
This class should have been already registered using registerClassAlias at
some earlier point in time.
c) populate the fields of that typed instance based on the value of the
fields during deserialization. Ideally this should happen during
deserialization directly into the new typed instance instead of creating
one generic object during deserialization and then using it to subsequently
populate the typed instance.

If you are using a 3rd party library then unless it has support for the
explicitType mappings (to retrieve from getClassByAlias) perhaps you will
need to work from the object structure with the _explictType fields and
recreate the typed object structure from it (again, it would be helpful if
the library had some sort of mapping to avoid this 'double handling'). This
could be more complicated if the inbound amf has instances with nested
custom class fields, but should be straightforward for basic value object
type scenarios (as per your Patient example).


Hopefully that makes sense.... let me know if I can clarify any of the
above.


cheers,
Greg



On Sun, Nov 13, 2016 at 5:27 AM, PKumar <pr...@gmail.com> wrote:

> Hi,
>
> I am working on amfjs integration and it almost done. but i need to map the
> java clas object to AS3 class object. I am getting the _explicitType from
> BlazeDS side but could not map it with AS3 object. i also used the
> registerClassAlias but nothing working. I attached the trace from chorme.
> Please suggest how can i do it in FlexJS.
>
> <http://apache-flex-users.2333346.n4.nabble.com/file/n14106/capture.png>
>
>
>
> -----
> Regards,
> Prashant
> --
> View this message in context: http://apache-flex-users.
> 2333346.n4.nabble.com/FlexJS-AMFJS-Class-Mapping-tp14106.html
> Sent from the Apache Flex Users mailing list archive at Nabble.com.
>