Skip to content

Instantly share code, notes, and snippets.

Created October 28, 2010 01:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/650417 to your computer and use it in GitHub Desktop.
Save anonymous/650417 to your computer and use it in GitHub Desktop.
Serialize and Deserialize Object
@SuppressWarnings("unchecked")
private static final <GPType> GPType serialzeAndDeserialize(GPType obj) throws Exception {
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
ObjectOutputStream stream = new ObjectOutputStream(byteStream);
stream.writeObject(obj);
ByteArrayInputStream byteInputStream = new ByteArrayInputStream(byteStream.toByteArray());
ObjectInputStream inputStream = new ObjectInputStream(byteInputStream);
return (GPType) inputStream.readObject();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment