File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

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: 15092

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 8 API documentation
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46380
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:
subject: How to create object as Serializable?
It's not a secret anymore!