Wowza Community

Java to AS3 custom object serialization

Hi, I just recently dropped Red5 server inorder to develop on much more production level platform… Wowza. I am in the middle of converting some of server side code. So far I have found everything I needed, and more (that I plan on playing with later).

Mostly I am working with server side remote calls, and client custom methods. IE. IClient.call() methods.

I am stuck on serializing my custom objects from java to actionscript. It would appear that this functionality doesn’t exist. Simply put I was hoping to be able to take a custom java object like:

package com.company;

class MyCustom implements Serializable

{

public String field1;

}

And then pass an instance to IClient.call() method. Then on the actionscript side have an AS class:

[Bindable]

[RemoteClass(alias=“com.company.MyCustom”)]

public class MyCustomClass

{

public var field1:String;

}

Right now its choking because when i pass an instance of MyCustom to IClient.call(), it proceeds to create AMFData objects out of it by using:

class AMFUtils

static AMFData[] convertParams(Object[] params)

which takes MyCustom Object and makes it a String using the toString() method. So on the actionscript side the object comes out as a String instead of the ActionScript object MyCustomClass.

Without wowza source it is very difficult to see if there is a way to do this. I have a feeling this functionality is not implemented in wowza yet. This does work in Red5 btw. I was hoping there was even a method somewhere to take a custom object class and make a AMFDataObj out of it with the keys being field names, and values being the params. (Basically serializer) I will probably end up writing one on my own unless there is more standard way that wowza has to handle this.

Much appriciated for any ideas, help.

Thanks,

Bobby

We do not currently have a way to do this. You must marshal your objects back and forth between Java and Flash. On the Wowza Pro side you need to use the AMFData(*) classes. They will end up on the Flash side as Objects that will need to be marshalled to ActionScript objects.

I have spent a little time on this but have not found a solution. It is something we do plan on working on in a future version of Wowza Pro. For now marshalling is required.

Charlie

This is great info. It might be a little while before I get to it but when I get a chance I will take a look at it.

Charlie

It is not something we are currently working on.

Charlie

Bobby,

AMF3 is the default, so you don’t have to do anything. Do make sure you are not setting it to AMF0 somewhere in your Flash app, because it used to be necessary and there is Flash code floating around with this setting.

And take a look at the ServerSideModules example:

[wowza-install-dir]/examples/ServerSideModules.

This example includes a Flash client and Wowza module to demonstrate how to pass data back and forth to Wowza.

Richard

Thanks for quick reply. I figured this was the case. I was wondering if you could help me a bit to understand how the marshling works from Java to AS. Currently i am trying to create a AMFDataObj, but it seems to come out the other side as a long list of objects or something. Its very strange.

Anyways is there a flag to set AMF3 somewhere as well, or do we have to get down to low level encoding/decoding? If thats so, can i still use the call() or is there something else.

thanks,

Bobby

Charlie, i have figured out how to pass objects to Flash from Wowza and have them de-serialize automatically on the flash side. There is just one problem, for some reason I am getting an additional parameter added. “0”, probably null actually.

Basically i call

AMFData obj = AMFUtils.encodeCustomObject(account);

client.call(“notify_userDataUpdate”, null, obj);

And on the flash side the function is:

public function notify_userDataUpdate(account:Account, msg:String = null, quiet:Boolean = false):void

the msg var is being set to “0” even though there is only 1 param on the client.call side. This isn’t too big deal as i could just put a dummy var in between, but maybe we can get it fixed and maybe even provide a perm solution to this now as most people seem stuck on this.

Here is the encoding function i wrote. It currently ignores static fields, and doesn’t send transient data.

Let me know what you think.

Bobby

		if (o instanceof Iterable)
		{
			AMFDataArray list = new AMFDataArray();
			for (Object oo : ((Iterable)o))
				list.add(encodeCustomObject(oo));
			return list;
		}
		if (o instanceof Array)
		{
			AMFDataArray array = new AMFDataArray();
			int len = Array.getLength(o);
			for (int i=0;i<len;i++)
				array.add(encodeCustomObject(Array.get(o, i)));
			return array;
		}
		
		
		if (o instanceof Boolean)
			return new AMFDataItem((Boolean)o);
		if (o instanceof Date)
			return new AMFDataItem((Date)o);
		if (o instanceof Double)
			return new AMFDataItem((Double)o);
		if (o instanceof Integer)
			return new AMFDataItem((Integer)o);
		if (o instanceof Long)
			return new AMFDataItem((Long)o);
		if (o instanceof String)
			return new AMFDataItem((String)o);
		
		//NULL
		if (o == null)
			return new AMFDataItem();
		
		
		AMFDataObj obj = new AMFDataObj();
		
		Class c = o.getClass();
		obj.setClassName(c.getName());
		
		System.out.println("Encoding: "+c.getName());
		Field[] fields = c.getFields();
		for (Field f : fields)
		{
			//Skip static fields
			if ( (f.getModifiers() & Modifier.STATIC) == 0)
			{
				obj.getTrait().addMember(f.getName());
				
				try{
					if ( (f.getModifiers() & Modifier.TRANSIENT) == 0)
						obj.put(f.getName(), encodeCustomObject(f.get(o)));
					else
						obj.put(f.getName(), new AMFDataItem()); //Don't Send Any Value (transient)
				}
				catch(Exception e)
				{
					e.printStackTrace();
				}
			}
		}
		
		return obj;
	}

We do not currently have a way to do this. You must marshal your objects back and forth between Java and Flash. On the Wowza Pro side you need to use the AMFData(*) classes. They will end up on the Flash side as Objects that will need to be marshalled to ActionScript objects.

I have spent a little time on this but have not found a solution. It is something we do plan on working on in a future version of Wowza Pro. For now marshalling is required.

Charlie

Hi,

Is there a chance for class maping being possible in a close future?

thanks,

Pierre.

Charlie, i have figured out how to pass objects to Flash from Wowza and have them de-serialize automatically on the flash side. There is just one problem, for some reason I am getting an additional parameter added. “0”, probably null actually.

Basically i call

AMFData obj = AMFUtils.encodeCustomObject(account);

client.call(“notify_userDataUpdate”, null, obj);

Thank you. It’s works realy.