Skip to content

Instantly share code, notes, and snippets.

@kolemannix
Created November 29, 2018 13:06
Show Gist options
  • Save kolemannix/c3292c9fed1a9292d099d5af8159d550 to your computer and use it in GitHub Desktop.
Save kolemannix/c3292c9fed1a9292d099d5af8159d550 to your computer and use it in GitHub Desktop.
// type annotation is added for clarity and is not needed
implicit val pointTrySerializable: SafeSerializable[Point, Try] = SafeSerializable.makeTry[Point](
serializePoint, deserializePoint
)
val result: Try[Array[Byte]] = Serializer.serialize(point)
result match {
case Success(bytes) =>
// type annotation is actually needed! We have to tell `deserialize` what type
// we want back
val deserialized: Try[Point] = Serializer.deserialize(bytes)
println("Success? " + deserialized.isSuccess)
case Failure(ex) => ex.printStackTrace
}
> "Success? true"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment