• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Serialization/deserialization

 
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there any way to deserizalize object and use him without that object's class declaration (or without having .class file)?
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To my knowledge, You will need the class declaration in order to deserialize, since you will at some time attempt to load the class and reference it from the deserialization process.
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are right. Without definition I wouldn't be able to make the reference variable.
But without casting deserialization will be successfull. Won't it?
 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lukas Smith wrote:You are right. Without definition I wouldn't be able to make the reference variable.
But without casting deserialization will be successfull. Won't it?


Have you actually tried it? It would be very easy to test. Just serliase an object and then try to deserialize it, but using a classpath that has the class missing.

Or even just look at the API for ObjectInputStream. (clue:what exceptions are thrown by readObject()?)

J.
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SerializationException

But you may not understand me.

Look at that:
person A sends the serialized object to person B. It is one file.
Then people B is going to deserialize it:

Pseudo code:


I cannot cast obj to its type. I have no definition of him.
So to deserialize object and take his full abilities I must have its definition.
Am I wrong?
 
Jason Irwin
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lukas Smith wrote:SerializationException


Wrong. I suggest you go and read the API Documentation
One of the 5 exceptions thrown by that method will tell you your answer.

person A sends the serialized object to person B. It is one file.
Then people B is going to deserialize it:

Pseudo code:I cannot cast obj to its type. I have no definition of him.
So to deserialize object and take his full abilities I must have its definition.
Am I wrong?


The fact that you cannot cast to the type is not the issue, the fact that line 4 will not complete is the issue.
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why the line 4th will not complete?
ClassNotFoundException will be thrown?
So I must have the serialized object definition.
 
Jason Irwin
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Correct, and you can see this exact behaviour if you run a test like I suggested.
reply
    Bookmark Topic Watch Topic
  • New Topic