views:

314

answers:

2

Is it possible to receive custom generic typed objects through AMF? I'm trying to integrate a flex app with an existing C# service but flex is choking on custom generic typed objects. As far as I can tell Flex doesn't even support generics, but I'd like to be able to even just read in the object and cast its members as necessary. I basically just want flex to ignore the <T>. I'm hopeful that there's a way to do this, since flex doesn't complain about typed collections (a server call returning List works fine and flex converts it to an ArrayCollection just like an un-typed List).

Here's a trimmed down example of what's going on for me:

The custom C# typed class

   public class TypeTest<T>
    {
        public T value { get; set; }

        public TypeTest ()
        {
        }
    }

The server method returning the typeTest

    public TypeTest<String> doTypeTest()
    {
        TypeTest<String> theTester = new TypeTest<String>("grrrr");

        return theTester;
    }

The corresponding flex value object:

[RemoteClass(alias="API.Model.TypeTest")]
    public class TypeTest
    {
        private var _value:Object;

        public function get value():Object
        {
             return _value;
        }

        public function set value(theValue:Object):void
        {
            _value = value;
        }

        public function TypeTest()
        {
        }
    }

and the result handler code:

public function doTypeTest(result:TypeTest):void 
{
    var theString:String = result.value as String;

    trace(theString);
}

When the result handler is called I get the runtime error:

TypeError: Error #1034: Type Coercion failed: cannot convert mx.utils::ObjectProxy@11a98041 to com.model.vos.TypeTest.

Irritatingly if I change the result handler to take parameter of type Object it works fine.

Anyone know how to make this work with the value object? I feel like i'm missing something really obvious.

A: 

Try receiving an ObjectProxy in the result handler and using the debugger to look at the contents of it. The proxy is likely for a ResultEvent or similar container class, rather than a plain TypeTest object.

Dan Monego
Thanks for the tip, but when I checked it out in the debugger the ObjectProxy that is returned looks like it is the actual TypeTest object. It has the value field accessible as result.value
Aaron
A: 

Hi Aaron,

I am facing the same issue. Can you please tell how you resolved the issue.

Thanks.

-H