How does the compiler find the implicit method for Json.obj()?


(joymufeng) #1

We could build a json object just like this:

import java.time.Instant
import play.api.libs.json.Json

object Test extends App {
  println(Json.obj("time" ->
  //Output: {"time":"2018-05-25T18:13:23.409Z"}

The signature of Json.obj() method is:

def obj(fields: (String, JsValueWrapper)*): JsObject

While the implicit method Json.toJsFieldJsValueWrapper is not in scope, how is converted to JsValueWrapper successfully ? Thanks in advance for your reply !

(joymufeng) #2

I get the answer from here Outer Objects for Nested Types. The reason is that the outer objects for nested types also contribute implicits.