Created
February 1, 2018 18:43
-
-
Save cvogt/ada28fff8f2cc53ddbf59c48e80468ae to your computer and use it in GitHub Desktop.
versioned serializers in scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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