Q:

Casting java.lang.Object to custom object raises ClassCastException

So, this is an oddball issue. I work in an embedded environment and I'm trying to send a message (object) from one application to another application. API-standard objects such as java.lang.String will work just fine, but when I try to send an object fo a custom class, a ClassCastException is raised.
Here's the setup: I have a sender application and a receiver application. In the sender application, I instantiate an UserUAI object (a custom class included in a library I wrote), cast it to Object and send it to the receiving application using the supporting class ComManager included in the environment API. But that's ok, it works fine, and like I said before, if I use API-compliant objects, I have no problem whatsoever.
Sending end:
UserUAI userUAI = new userUAI(/*param list*/);
ComManager.getInstance().sendMessage(targetAppPID, userUAI);
//method signature: void sendMessage(String targetAppPID, Object message)

Receiving end:
Object received = (UserUAI)receiver.getReceivedMessage(); 
UserUAI userUAI = (UserUAI)received; //raises exception
//method signature: Object getReceivedMessage();

I checked, double checked and triple checked, the received object is of UserUAI type at runtime.
Also, I'm posting the results of a suggestion that Paŭlo Ebermann gave me:
received.getClass() -> class nddigital.support.ricoh.UserUAI
UserUAI.class -> class nddigital.support.ricoh.UserUAI 
received.getClass().getClassLoader() -> 
jp.co.ricoh.dsdk.osgi.service.multiXletManager.XletClassloader@2d4f9e 
UserUAI.class.getClassLoader -> 
jp.co.ricoh.dsdk.osgi.service.multiXletManager.XletClassloader@4464ab 
UserUAC.class == received.getClass() -> false 
UserUAC.class.getClassLoader() == received.getClass().getClassLoader() -> false
I hope someone out there can lend me a hand. I'll keep you posted.

A:

To qoute the Java Specification part of §4.3.4

Two reference types are the same run-time type if:
They are both class or both interface types, are defined by the same class loader, 
  and have the same binary name (§13.1), in which case they are sometimes said to be the 
  same run-time class or the same run-time interface.
They are both array types, and their component types are the same run-time type(§10). 

And in Casting Conversions it says.

If T is a class type, then R must be either the same class (§4.3.4) as T or 
  a subclass of T, or a run-time exception is thrown. 

So, since the same classes have been defined by different class loaders, its instances can not be cast to other.

