Question

I'm using BlazeDS to remote some Java objects that I'm consuming in a Flex application. I'm getting a type coercion error with one of my classes that I can't for the life of me figure out. I have other classes that are working fine using the same data types, and I've gone over my mapping a dozen times. I'm following all of the necessary conventions for getters and setters as far as I know...

Anyhow, my question is: how can I debug this problem? Running the Flex app in debug mode spits out some generic errors to the console that don't really help much (TypeError: Error #1034: Type Coercion failed: cannot convert Object@5d1d809 to valueObjects.SomeClass.).

I'm new to this whole AMF / Flex + Java thing, so any tips would be greatly appreciated.

Was it helpful?

Solution

These are two of the tools I use when working with BlazeDS, AMF, etc.:

  • Use an HTTP proxy tool that shows the calls between your client and server, like Charles

Charles is an HTTP proxy / HTTP monitor / Reverse Proxy that enables a developer to view all of the HTTP and SSL / HTTPS traffic between their machine and the Internet. This includes requests, responses and the HTTP headers (which contain the cookies and caching information).

  • Turn on the logging for BlazeDS. Within WEB-INF/conf/services-conf.xml, lower the debugging level to 'debug' like in the below snippit. The output, which is fairly detailed, will appear in {tomcat-home}/logs/localhost.yyyy-mm-dd.log

    <target class="flex.messaging.log.ConsoleTarget" level="debug">

OTHER TIPS

The easiest way to check on the communication between service-clients AMF messages is to use FireFox, install FireBug extension and add the AMF Explorer. You can see the structured requests and responses.

The java class that is being deserialized in the client side must have a reference to an object of the corresponding AS3 class in the application (mxml or as3). Otherwise, the as3 class will not be loaded in the swf file and will result in deserializing the java class to a generic as3 object.

updatedThis will happen despite having the mapping, getters and setters. Just declare an object of the corresponding AS3 class in script section of your mxml.

I use Flex Builder and have it set up for both client and server side debugging. It was a pain to set up at first, but you can Google for step-by-step tutorials. I find it quite valuable for debugging RPCs. Last I checked, Flex Builder has a free trial and is free to students and the unemployed.

It's also worth noting that instrumentation in Java can also cause a loss of information and/or interfere with the serialization process and stream.

I've experienced this TypeError: Error #1034: Type Coercion failed on a project (Flex<->BlazeDS+Spring) where our data-access layer was implemented with iBatis and had lazy-loading switched on - we turned it off as that measure represented the lesser loss of efficiency (theoretically, at least), as compared to other workarounds we had in place.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top