【问题标题】:Scala Play readNullable can't read Map typesScala Play readNullable 无法读取地图类型
【发布时间】:2019-06-21 02:15:46
【问题描述】:

我正在尝试使用 play.api.lib.json 将 json 转换为我的对象。但是后来发生了这种情况......

  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 _)
  }

Reads[Option[Map[String,String]]] 类型的表达式不适合期待类型 Reads[Foo]

【问题讨论】:

标签: scala playframework play-json


【解决方案1】:

您正在使用play-json 的函数式语法,但之前缺少导入:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-27
    • 1970-01-01
    • 1970-01-01
    • 2015-08-17
    • 1970-01-01
    • 2020-05-27
    • 1970-01-01
    相关资源
    最近更新 更多