Skip to content

Instantly share code, notes, and snippets.

@cvogt
Created February 1, 2018 18:43
Show Gist options
  • Save cvogt/ada28fff8f2cc53ddbf59c48e80468ae to your computer and use it in GitHub Desktop.
Save cvogt/ada28fff8f2cc53ddbf59c48e80468ae to your computer and use it in GitHub Desktop.
versioned serializers in scala
case class Foo( bar: Bar )
case class Bar( bar: Baz )
case class Baz( bar: Booyah )
case class Booyah( i: Int, s: String )
object V1Serializers{
implicit def FormatFoo[Foo] = ...
implicit def FormatBar[Bar] = ...
implicit def FormatBaz[Baz] = ...
implicit def FormatBooyah[Booyah] = ...
}
object V2Serializers{
implicit def FormatFoo[Foo] = ...
implicit def FormatBar[Bar] = ...
implicit def FormatBaz[Baz] = ...
implicit def FormatBooyah[Booyah] = ...
}
def serialize[T: Foo]( foo: Foo ): Json = ...
def sendToV1Server( foo: Foo, send: Json => () ) = {
import V1Serializers.FormatFoo
send( serialize( foo ) )
}
def sendToV2Server( foo: Foo, send: Json => () ) = {
import V2Serializers.FormatFoo
send( serialize( foo ) )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment