I'd like to define a class class for JSON serialisation like so:
case class Foo(id: String, variety: Variety)
sealed trait Variety
case object Bar extends Variety { override def toString = "1" }
case object Baz extends Variety { override def toString = "2" }
It should serialise and deserialise like this:
write[Foo](Foo("foo1", Bar))
"""{"id":"foo1", "variety":"1"}"""
read[Foo]("""{"id":"foo2", "variety":"2"}""")
Foo("foo2", Baz)
But it serialises to {"id":"foo2", "variety":{}}
and fails to deserialise. Is it possible to use case objects like this? I'm using lift-json_2.10 2.6-M2?
Is there a better way to handle enumerations with lift-json?