Skip to content

Instantly share code, notes, and snippets.

@franzejr
Last active August 29, 2015 14:22
Show Gist options
  • Save franzejr/5b520f57e455d00c5cfa to your computer and use it in GitHub Desktop.
Save franzejr/5b520f57e455d00c5cfa to your computer and use it in GitHub Desktop.
Serialize objects in Java
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(buffer);
oos.writeObject(objectToBeSerialized);
oos.close();
byte[] rawData = buffer.toByteArray();
//OR
byte[] data = SerializationUtils.serialize(objectToBeSerialized);
//Deserialize
YourObject yourObject = (YourObject) SerializationUtils.deserialize(byte[] data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment