I was playing around in the Play Framework's Scala console, and it looks like it's somehow doing implicit conversions without having any implicit defs in scope:
scala> import play.api.libs.json._
import play.api.libs.json._
scala> :implicits
No implicits have been imported other than those in Predef.
scala> Json.arr _
res0: Seq[play.api.libs.json.Json.JsValueWrapper] => play.api.libs.json.JsArray = <function1>
scala> Json.arr(1,2,3)
res1: play.api.libs.json.JsArray = [1,2,3]
As you can see, the output of :implicits
shows that the only implicit conversions in scope are those from scala.Predef
. However, somehow my Int
values (1,2,3) are being converted to play.api.libs.json.Json.JsValueWrapper
instances when I pass them to Json.arr()
.
I was under the impression that implicit conversions were only applied when the implicit conversion was in scope (i.e., it was declared or imported in the current scope). How then is this conversion happening?
Update: I think the Play console must be doing something because the conversion happens even if I open a fresh console and make a simple assignment (no imports at all):
scala> val x: play.api.libs.json.Json.JsValueWrapper = 1
x: play.api.libs.json.Json.JsValueWrapper = JsValueWrapperImpl(1)