Skip to content

Instantly share code, notes, and snippets.

@tobnee
Created August 12, 2015 10:53
Show Gist options
  • Save tobnee/30876d556f2714b08f39 to your computer and use it in GitHub Desktop.
Save tobnee/30876d556f2714b08f39 to your computer and use it in GitHub Desktop.
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