aspose file tools*
The moose likes Beginning Java and the fly likes How to create object as Serializable? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to create object as Serializable?" Watch "How to create object as Serializable?" New topic
Author

How to create object as Serializable?

Kathiresan Chinnasamy
Ranch Hand

Joined: Jan 01, 2008
Posts: 65
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

Joined: Aug 16, 2005
Posts: 14108
    
  16

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 ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38363
    
  23
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to create object as Serializable?