I am using Gson to serialize and deserialize objects, and saving the results in Redis. ie object is serialized into json string then put in Redis, when the object is retreived, it is string then I use Gson.fromjson(str, className) to deserialize into object.
I am beginner with Scala so I assume my usage is incorrect.
I have the following class:
case class Status(id: String, state: State)
where State is the following:
sealed trait State {}
case object COMPLETED_SUCCESSFULLY extends State {}
case object FINISHED_POLLING extends State {}
case object CURRENTLY_DOWNLOADING extends State {}
case object FINISHED_DOWNLOADING extends State {}
case object CURRENTLY_UPLOADING extends State {}
case object FINISHED_UPLOADING extends State {}
I want to serialize Status
into a json string then deserialize it back into an object.
But, when I serialize Status
using Gson, I get:
"{\"id\":\"foo\",\"state\":{}}"
Why is that?
Ex:
val Status = new Status("foo", COMPLETED_SUCCESSFULLY)
I expect the serialized output to be
"{\"id\":\"foo\",\"state\":\"COMPLETED_SUCCESSFULLY\"}"