Skip to content

Instantly share code, notes, and snippets.

@ShikaSD
Created March 31, 2020 15:45
Show Gist options
  • Save ShikaSD/e3cf3a005fc09c13cea5a916926e5644 to your computer and use it in GitHub Desktop.
Save ShikaSD/e3cf3a005fc09c13cea5a916926e5644 to your computer and use it in GitHub Desktop.
private object TestObject : Serializable
@Test
fun `object instance is the same after deserialization`() {
assertEquals(TestObject, serializeDeserialize(TestObject))
}
private fun serializeDeserialize(instance: Serializable): Serializable {
val out = ByteArrayOutputStream()
ObjectOutputStream(out).use {
it.writeObject(instance)
}
return ObjectInputStream(ByteArrayInputStream(out.toByteArray())).use {
it.readObject() as TestObject
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment