Announcement Announcement Module
Collapse
No announcement yet.
Deserializing complex beans Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Deserializing complex beans

    I am trying to retrieve a Data object, which has a List of Var objects and a List of Case objects. When I retrieve it it shows the Data object, but the two Lists are null.

    I think it is a client side problem, so I will start with my client side code first.

    The AS objects are generated from the java objects by Maven Flexmojos plugin and looks as follow
    Code:
    package com.example.module.statistics.model {
    
        [Bindable]
        [RemoteClass(alias="com.example.module.statistics.model.Data")]
        public class Data extends DataBase {
        }
    }
    Code:
    package com.example.module.statistics.model {
    
        import flash.utils.IDataInput;
        import flash.utils.IDataOutput;
        import flash.utils.IExternalizable;
        import mx.collections.ListCollectionView;
    
        [Bindable]
        public class DataBase implements IExternalizable {
    
                private var _cases:ListCollectionView;
                private var _vars:ListCollectionView;
    
        public function DataBase()
        {
            super();
        }
        
    
            public function get cases():ListCollectionView {
                return _cases;
            }
    
            public function get vars():ListCollectionView {
                return _vars;
            }
    
            public function readExternal(input:IDataInput):void {
                _cases = input.readObject() as ListCollectionView;
                _vars = input.readObject() as ListCollectionView;
            }
    
            public function writeExternal(output:IDataOutput):void {
                output.writeObject(_cases);
                output.writeObject(_vars);
            }
        }
    }
    And Var:
    Code:
    package com.example.module.statistics.model {
    
        [Bindable]
        [RemoteClass(alias="com.example.module.statistics.model.Var")]
        public class Var extends VarBase {
        }
    }
    Code:
    package com.example.module.statistics.model {
    
        import flash.utils.IDataInput;
        import flash.utils.IDataOutput;
        import flash.utils.IExternalizable;
    
        [Bindable]
        public class VarBase implements IExternalizable {
    
                private var _keep:Boolean;
                private var _name:String;
                private var _type:String;
    
        public function VarBase()
        {
            super();
        }
        
    
            public function set keep(value:Boolean):void {
                _keep = value;
            }
    
            public function get name():String {
                return _name;
            }
            public function set name(value:String):void {
                _name = value;
            }
    
            public function get type():String {
                return _type;
            }
            public function set type(value:String):void {
                _type = value;
            }
    
            public function readExternal(input:IDataInput):void {
                _keep = input.readObject() as Boolean;
                _name = input.readObject() as String;
                _type = input.readObject() as String;
            }
    
            public function writeExternal(output:IDataOutput):void {
                output.writeObject(_keep);
                output.writeObject(_name);
                output.writeObject(_type);
            }
        }
    }
    I omitted Case, it looks like Var.

    Then I have a Facade in AS which calls the service at the server side:

    Code:
    package com.example.statistics.facade {
    
        import mx.rpc.AsyncToken;
        import mx.rpc.events.ResultEvent;
        import flash.utils.ByteArray;
        import com.example.flexmodules.remoteservice.RemoteService;
        import com.example.module.statistics.model.Data;
    
        public class StatisticsFacade extends RemoteService {
    
            public function StatisticsFacade() {
                super("flexStatisticsFacadeImpl", "secureStatisticschannel", "http://localhost:8081/statistics-webapp-4.0.0-SNAPSHOT/messagebroker/securestatisticschannel", false);
            }
    
            public function convertData(filename : String, data : ByteArray, callback : Function) : void {
                var token : AsyncToken = remoteObject.convertData(filename, data);
                var listener : Function = function(event : ResultEvent) : void {
                    if (event.token == token) {
                        remoteObject.removeEventListener(ResultEvent.RESULT, listener);
                        callback(event.result as Data);
                    }
                }
                remoteObject.addEventListener(ResultEvent.RESULT, listener);
            }
        }
    }
    And a RemoteService with some basic code:
    Code:
    package com.example.flexmodules.remoteservice {
    
        import mx.core.Application;
        import mx.messaging.Channel;
        import mx.messaging.ChannelSet;
        import mx.messaging.channels.AMFChannel;
        import mx.messaging.channels.SecureAMFChannel;
        import mx.rpc.events.FaultEvent;
        import mx.rpc.remoting.mxml.RemoteObject;
    
        import com.example.flexmodules.remoteservice.events.RemoteExceptionEvent;
    
        public class RemoteService {
    
            protected var remoteObject : RemoteObject;
    
            /**
             * Constructor for the actual RemoteObject to create. An event listener
             * is added for exceptions.
             * @param id String representing the id of the new RemoteObject to create
             * @param channelname String representing the channelname of the new RemoteObject to create
             * @param destination String representing the destination of the RemoteObject to create
             * @param secure Boolean representing whether or not the RemoteObject should setup a secure channel
             */
            public function RemoteService(id : String, channelname : String, destination : String, secure : Boolean) {
                remoteObject = new RemoteObject(id);
                remoteObject.showBusyCursor = true;
                remoteObject.channelSet = new ChannelSet();
                var channel : Channel;
                if (secure) {
                    channel = new SecureAMFChannel(channelname, destination);
                } else {
                    channel = new AMFChannel(channelname, destination);
                }
                remoteObject.channelSet.addChannel(channel);
                remoteObject.addEventListener(FaultEvent.FAULT, onRemoteException);
            }
    
            /**
             * Generic fault event handler for all remote object actions. Based on the received message an action
             * is taken, mostly throwing a new event.
             * @param event FaultEvent received for handling
             */
            public function onRemoteException(event : FaultEvent) : void {
                trace('code : ' + event.fault.faultCode + ', message : ' + event.fault.faultString + ',detail : ' + event.fault.faultDetail);
    
                Application.application.dispatchEvent(new RemoteExceptionEvent(RemoteExceptionEvent.REMOTE_EXCEPTION, "Unknown problem occurred during a remote call : " + event.fault.message));
            }
        }
    }
    When I run this, I see at the server side that the Var list has a few items in it. When I look at the client side the vars list is null.

    Do I just have the complete wrong way of doing this, or am I missing something about deserialization?

  • #2
    I am having the same problem any solution

    Comment


    • #3
      It's hard to say what could be wrong without analyzing the code in detail, but to suffice to say, you should certainly be able to map such hierarchies. In the example above, part of the problem might be the use of ListCollectionView instead of ArrayCollection. See the BlazeDS type conversion guide for how such types are mapped:

      http://livedocs.adobe.com/blazeds/1/..._2.html#312520

      Comment

      Working...
      X