Created
August 12, 2015 10:53
-
-
Save tobnee/30876d556f2714b08f39 to your computer and use it in GitHub Desktop.
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
sealed trait Drink | |
case object Beer extends Drink | |
case object Wine extends Drink | |
case class OrderDrinkV1(drink: Drink) | |
case class DrinkOrderedV1(drink: Drink) | |
object TestApp extends App { | |
import scala.pickling.Defaults._ | |
import scala.pickling.json._ | |
val order = OrderDrinkV1(Beer) | |
val json = order.pickle.value | |
val anyRefValue = JSONPickle(json).unpickle[AnyRef] | |
val drink = anyRefValue.asInstanceOf[OrderDrinkV1].drink | |
// ok | |
assert(drink.getClass == Beer.getClass) | |
// fails and would work if the unpickle would target OrderDrinkV1 and not AnyRef | |
assert(drink == Beer) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment