Working on play ws and have to prepare request param as {"initVideoUploadParams": {"videoMetadataParams":{"metadata":{"name":"","description":""}}}} . Tried the solution given in the link but didn't worked as my case is not similar to that question. Below is the code snippet
ws.url(savaUrl+configObj.get[String]("kaltura.init"))
.post(Map("initVideoUploadParams" -> InitVideoUploadParams(fileName,fileName)))
And the case class
case class InitVideoUploadParams(name:String,desc:String)
object InitVideoUploadParams {
implicit object InitVideoUploadParamsWrites {
def writes(name:String,desc:String): JsObject = Json.obj(
"videoMetadataParams" -> VideoMetadataParams(Utils.createVideoParamsMap(name,desc)).metadata
) } }
case class VideoMetadataParams(metadata: Map[String, String])
object VideoMetadataParams { implicit object VideoMetadataParamsWrites {
def writes(metadata:Map[String,String]): JsObject = Json.obj(
"metadata" -> metadata
) } }
Gone through the play documentation but not able to implement. Help me to understand what is wrong with my code.
You're trying to POST
a value of type Map[String, InitVideoUploadParams]
with Play-WS. In order for Play to know how to serialize that type to JSON, there needs to be an object of type Writes[InitVideoUploadParams]
in the implicit scope. Apparently you were trying to do that with those implicit object
s, but you need to extend Writes
for that to work:
import play.api.libs.json.Writes
object InitVideoUploadParams {
implicit object InitVideoUploadParamsWrites extends Writes[InitVideoUploadParams] {
def writes(o: InitVideoUploadParams): JsValue = {
??? // implementation goes here
}
}
}
But it's a bit simpler to instead use the methods on the Writes
companion object:
import play.api.libs.json.Writes
object InitVideoUploadParams {
implicit val writes: Writes[InitVideoUploadParams] = Writes { o =>
??? //implementation goes here
}
}