Scala Play readNullable can't read Map types

Viewed 156

I am trying to use play.api.lib.json to convert a json to my object. But then this happend...

  case class Foo(foo:Option[Map[String,String]])
  case class Bar(bar:String,foo:Foo)

  def barJsonToModel(foobarJson:JsValue):Bar = {
     implicit val fooReads: Reads[Foo] = (
        ( JsPath \ "foo" ).readNullable[Map[String,String]]
     )(Foo.apply _)
  }

Expression of type Reads[Option[Map[String,String]]] doesn't comfort to expect type Reads[Foo]

1 Answers

You are using the functional syntax of play-json, but so an import is missing before:

import play.api.libs.functional.syntax._
Related