• Post Reply Bookmark Topic Watch Topic
  • New Topic

Custom Serialization  RSS feed

 
Salman Mushtaq
Greenhorn
Posts: 27
Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !
as i know in java serialization process is automatic it means that java will automatically serailzed a sepecified object , my question is that how can i gain a custom control on serialization process so that object will be serialized as per my command?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly do you mean with "serialization is automatic"? Java objects are not automatically serialized somehow.
 
Ashish Dutt
Ranch Hand
Posts: 172
Java MySQL Database Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed with Jesper
Java objects are not automatically serializable
You have to explicitly declare the serializable interface in the class for example
Also please note, this interface has no methods to override its just a marker interface that tell the JVM that you are going to serialize the object
Once this is done then you can use any of the wrapper classes to save the object state and then if you want you can deserialise it for later
 
Salman Mushtaq
Greenhorn
Posts: 27
Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes , but after it if i want that some instance variable of object can't serialized than what can i do ?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you'll have to make sure that the types (classes) of the instance variable are Serializable too, or make those instance variables transient, which means they won't be serialized.
 
Salman Mushtaq
Greenhorn
Posts: 27
Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok , can you tell me about Externalizable interface and readExternal() and writeExternal() ?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Salman Mushtaq wrote:ok , can you tell me about Externalizable interface and readExternal() and writeExternal() ?

Did you start with the API? If not, you should. If you have specific questions, ask those.

Very vague, open, random questions usually won't get you much of a response here, especially if you don't ShowSomeEffort.
 
Salman Mushtaq
Greenhorn
Posts: 27
Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:
Salman Mushtaq wrote:ok , can you tell me about Externalizable interface and readExternal() and writeExternal() ?

Did you start with the API? If not, you should. If you have specific questions, ask those.

Very vague, open, random questions usually won't get you much of a response here, especially if you don't ShowSomeEffort.


Dear i search on custom serialization and i get some information about that interface , if we want custom serialization that we implement Externalizable interface instead of Serializeable , and also about method but i did not find any detail of method which i write before , that why i ask here this is not random question , i think this is related to custom serialization so that is why i ask .
 
Paul Clapham
Sheriff
Posts: 22839
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't find out any details about that interface? I find that very surprising. I used the search keywords "java externalizable" and I got a link to its API documentation as the first choice. I also got a link to what claims to be a tutorial about it.
 
manish ghildiyal
Ranch Hand
Posts: 136
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To get control over serialization process, either you need to make those fields transient which you don't want to be serialized OR you need to implement writeReplace and readResolve methods in youe class.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!