Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to create object as Serializable?

 
Kathiresan Chinnasamy
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

How to make a object as Serializable..
For Example i got an object(Where the class didn't serializable) in main Class ... i have to serializable this object..

Can anyone help me ?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15366
40
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just make the class implement the interface Serializable:

Note that the interface doesn't have any methods, so you don't need to implement any methods.

Note: If you cannot modify the class, then it's not going to be possible. You can't make any object serializable.
[ June 23, 2008: Message edited by: Jesper Young ]
 
Campbell Ritchie
Sheriff
Pie
Posts: 49411
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
More a beginner's question.

In theory it is easy; you just add "implements Serializable" after the class name. Serializable is a tagging interface (also called a marker interface) which has no methods.

In practice you need to ensure that all its fields are instances of Serializable classes too.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic