File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Not serializable objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Not serializable objects" Watch "Not serializable objects" New topic
Author

Not serializable objects

Bernard Sigmund Gustav
Ranch Hand

Joined: Dec 20, 2005
Posts: 170
Hello,

I am having trouble saving objects into a blob.
I get the NotSerializableException.
From what I have gathered, the object I am trying to save cannot be serialized. I also cannot serialize it since it is an automatically generated object from an SDK i have no control over. What I am trying to do is find a workaround on how to save an object into a blob without serializing it. Can someone help me with this please?

Thank you
suji kumar
Greenhorn

Joined: Nov 08, 2006
Posts: 10
If you want to store an object itself, it has to be serializable
If it is not possible for you to make it serializable, you have to store each and every state of an object into a file, and when you want the object back , you have to create a new object and flush tht object with stored states
Bernard Sigmund Gustav
Ranch Hand

Joined: Dec 20, 2005
Posts: 170
hi suji

i am not sure what you mean by store each and every state into a file
Bernard Sigmund Gustav
Ranch Hand

Joined: Dec 20, 2005
Posts: 170
help
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
It sounds like it will not be possible to use standard Java serialization here. However one simple-to-use alternative would be to use XStream to convert the object to an XML representation instead. (See the two minute tutorial, it's very easy to use.) In this case you don't really need a BLOB - character-based types like CLOB or VARCHAR might be slightly more appropriate. But BLOB would still work.


"I'm not back." - Bill Harding, Twister
Bernard Sigmund Gustav
Ranch Hand

Joined: Dec 20, 2005
Posts: 170
thanks. i'll take a look at that one and see what i can do.
Bernard Sigmund Gustav
Ranch Hand

Joined: Dec 20, 2005
Posts: 170
hi,

can anyone help me with xtream?
i read their 2 minute tutorial and its different from what i have.
i dont have a class, and i just implement an interface.
that interface produces a template object which i have to save into a Blob in Oracle. i need to serialize that object for it be saved into oracle.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[Bernard]: i dont have a class, and i just implement an interface.

If you have an object, it must be a concrete class instance. That class may implement an interface, and maybe you don't know what the class is (perhaps it's anonymous, for example), but there is a class of some sort. You could call getClass() to find out what it is, exactly.

Regardless, You don't need to know the class to make this work. Skipping past various ways that you could customize the process, you can just use

I chose UTF-8 because that's a common encoding guaranteed to always work, for any strange character that may be present. You can probably replace it with something else if you want.

Later you can reverse the process:

If this isn't working for you, please provide more detail about what exactly goes wrong.
Bernard Sigmund Gustav
Ranch Hand

Joined: Dec 20, 2005
Posts: 170
Hi Jim,

Thanks for the explanation.

My object is a fingerprint template. I just learned that it can't be serialized because it is a set of mathematical equations. The fingerpitn kinda gets encrypted resulting in the fingerprint template. And it needs to be saved into a blob. So far, I have found no way of saving an object into a blob without serializing it, except maybe for xtream which i learned here, and i am still exploring it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not serializable objects