I can't seem to find a proper way to serialize my Map to a JSON object, when it has different types for the value, i.e.:
var user: Map[String, Any] = Map("name" -> "1", "id" -> 1)
val json: JsValue = Json.obj(
"user" -> user
)
produces:
type mismatch;
found : Map[String,Any]
required: play.api.libs.json.Json.JsValueWrapper
Or, if I use instead Map[String,AnyVal]
, it produces:
the result type of an implicit conversion must be more specific than AnyVal
But if I use either Map[String,Number]
or Map[String,String]
it works.
What am I missing, is there some wrapper I can call to safely use both numbers and integers on my JSON.obj() call?