user4833870
user4833870

Reputation:

Serialisation/deserialisation for sealed traits with Upickle

I am trying to call a webservice from my play server I am using upickle for serialisation/deserialisation . My problem I have a sealed trait as

sealed trait RequestContent {
}
case class CreateUserRequest (email: String, password: String,jsonBlob: Map[String, String], createBTCWallet: Boolean) extends RequestContent

And when I try using upickle.default.write as

val userRequest = CreateUserRequest("email","pw",Map("name" -> "name", true))
write(userRequest) 

it gives an extra key for $type. Is there a way to get the data to post without type in upickle??

Upvotes: 1

Views: 457

Answers (1)

sjrd
sjrd

Reputation: 22085

In the case of a sealed trait hierarchy, uPickle needs an additional $type field to be able to deserialize, since it needs to know which subclass to instantiate.

So the presence of this extra key is perfectly normal and necessary. It is not possible to remove it, as that would prevent deserialization from working.

Upvotes: 1

Related Questions