1

I have a program that sends POJO from a server to a client. For primitive data types like String[] or Boolean it works fine. When I create a custom data type with just getters and setters, send it from server to client and try to cast it from a Java Object to my data type I get exception:

java.lang.ClassCastException: java.lang.Object cannot be cast to com.ais.sqar.datatypes.Udata

Where on both instances of the client and server I can cast just fine. It seems when I push it across an ObjectOutputStream something strange happens. I have also serialized object as well. Any gotchas here with ObjectOutputStreams?

Asaph
  • 159,146
  • 25
  • 197
  • 199
  • 1
    You are doing something strange, resulting in a `new Object()` to be created instead of your `Udata`. Show code. – Paŭlo Ebermann Jul 14 '11 at 15:21
  • 2
    This should work fine. The problem seems to be that type assigned by the serialization mechanism to the object you are deserializing on the client is java.lang.Object rather than the type you are expecting. Can you post the code you are using at each end? Are you overriding the serialization machinery in any way? – antlersoft Jul 14 '11 at 15:26
  • 1
    Do you have the same class version on both ends in the classpath? – Angel O'Sphere Jul 14 '11 at 15:47

1 Answers1

0

Refer this tutorial http://java.sun.com/developer/technicalArticles/Programming/serialization/ to check if you are making any mistake while doing serialization.

Shekhar
  • 5,771
  • 10
  • 42
  • 48
  • Thanks Paulo. You were right. I was actually returning the wrong object in some method. Human error. This should be deleted in time. – Chris Campos Jul 14 '11 at 19:56