1

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??

NIMISHAN
  • 1,265
  • 4
  • 20
  • 29

1 Answers1

1

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.

sjrd
  • 21,805
  • 2
  • 61
  • 91
  • If i am getting this right then in that case i have no way to use upickle to post data to remote web service. –  Dec 21 '15 at 11:35
  • Not by using the default picklers/unpicklers for sealed traits. uPickle was not designed for this use case, but rather for a use case where uPickle is also use to deserialize on the other side. You could however write a [custom pickler](http://lihaoyi.github.io/upickle-pprint/upickle/#CustomPicklers) for your sealed trait, that would do exactly what you want. – sjrd Dec 21 '15 at 14:47