aspose file tools*
The moose likes Distributed Java and the fly likes Runtime API to find if the object is serialzable or not Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Runtime API to find if the object is serialzable or not" Watch "Runtime API to find if the object is serialzable or not" New topic
Author

Runtime API to find if the object is serialzable or not

K Abhijit
Ranch Hand

Joined: Mar 03, 2008
Posts: 88
Do we have any api which would tell us in runtime whether the object is serelizable or not?

something like this...

i am receiving object reference runtime which i am not aware whether is is serializable or not...

is there any way to find it out?


baseClassReference = ObjectReceivedByRuntime;


http://www.coderanch.com/t/417840/java-programmer-SCJP/certification/Serializable-issues


“The difference between 'involvement' and 'commitment' is like an eggs-and-ham breakfast: the chicken was 'involved' - the pig was 'committed'.”
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12674
    
    5
Use the instanceof operator to determine if an object implements Serializable just as you would to determine class and inherited types.

Naturally you are depending on the designer of the class to use the Serializable marker interface correctly.

Bill

Java Resources at www.wbrogden.com
K Abhijit
Ranch Hand

Joined: Mar 03, 2008
Posts: 88


import java.io.InputStream;
import java.io.Serializable;
import java.sql.Connection;



class Base implements Serializable{

// assume this class is serializable

}

class Derived extends Base {

Connection con = null;
InputStream in =null;
// is thi class serializable too? noway... as input stream and connection are not serializable object...
// but System.out.println(b instanceof Serializable); == true;


}
public class TestSerializableSubClass {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Base b = new Derived();
System.out.println(b instanceof Serializable);

}

}


please advise ......
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12674
    
    5
Advise? Like I said - you depend on the designer to use Serializable correctly.

You could try writing the object to an ObjectOutputStream - an exception you could catch would be thrown.

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Runtime API to find if the object is serialzable or not
 
Similar Threads
SERIALIZABLE CLASSES
Serializable issues !!
Serializing an object with out implementing Serializable
Server side implications of J2ME
Passing my object to one to other activity