PDA

View Full Version : AMF Object Serialization bug



SteveMercer
17 Jul 2014, 4:52 AM
Whilst using AMF objects with ext-js I noted the following...

If you create a normal javascript object and populate it you can pass this object via AMF to a back end script.

If you use the preferred Sencha way of defining and creating an object then it will not serialize properly to pass via AMF.

This works:

var request =
{
id : '1234',
param : 'Steve',
$flexType : 'Location.Classes.Testing.DataRequest'
};

as does:

var request = {};
request.id = '1234';
request.param = 'Steve';
request.$flexType = 'Location.Classes.Testing.DataRequest';

But these do not:

Ext.define('DataRequest',
{
id: '',
param: '',
$flexType : ''
});

var request = Ext.create('DataRequest');
request.id = '1234';
request.param = 'Steve';
request.$flexType = 'Location.Classes.Testing.DataRequest';


nor does:

var request = Ext.create('DataRequest',
{
id : '1234',
param : 'Steve',
$flexType : 'Location.Classes.Testing.DataRequest'
});


Are we doomed to just creating standard javascript objects to make this work?

evant
17 Jul 2014, 4:56 AM
There's a great deal of extra work that goes into defining a class, so you can't just rely on the standard JSON serialization because there are many more properties that get poked onto the object. Assuming you did want to use classes like that, you should have some kind of serialization method on the class that ends up producing a simple object literal that can be consumed/encoded easily.