Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing Serializable object to file with some data excluded

I have an object which allows me to store BufferedImage into my object file. In the same object I have BufferedImage variable which I use to cache the image after it's loaded first time from raw data array. Everything works fine when I'm creating object and storing it to file, since BufferedImage is null. The problem comes when I'm updating loaded object and the variable is being initialized and I want to save the object after it's updated.

Is there any possibility to store the serializable object to file, excluding some of the variables? Or maybe I can reset somehow my BufferedImage variable when storing to file?

Thanks in advance, Serhiy.

like image 626
Serhiy Avatar asked Feb 18 '11 12:02

Serhiy


1 Answers

you should mark the attribute you don't want to serialize as transient :

private transient BufferedImage image;
like image 117
JB Nizet Avatar answered Oct 21 '22 12:10

JB Nizet