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 <[email protected]> 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.
>

Reply via email to