Just another site

find object can’t be serialized

I encountered a problem today :one of the object can't be serialized, then I found
this useful code on from
       public static final Object clone(Serializable in) {
            try {
                ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
                ObjectOutputStream outStream = new ObjectOutputStream(byteOutStream);
                ByteArrayInputStream byteInStream =
                    new ByteArrayInputStream(byteOutStream.toByteArray());
                ObjectInputStream inStream = new ObjectInputStream(byteInStream);
                return inStream.readObject();
            } catch (OptionalDataException e) {
             throw new RuntimeException("Optional data found. " + e.getMessage()); 
            } catch (StreamCorruptedException e) {
             throw new RuntimeException("Serialized object got corrupted. " + e.getMessage());
            } catch (ClassNotFoundException e) {
             throw new RuntimeException("A class could not be found during deserialization. " + e.getMessage()); 
            } catch (NotSerializableException ex) {
             throw new IllegalArgumentException("Object is not serializable: " + ex.getMessage());
            } catch (IOException e) {
             throw new RuntimeException("IO operation failed during serialization. " + e.getMessage()); 

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: