如何解决以下隐式冲突?我使用Json.toJson将Double转换为JsValue。反向过程无效。存在隐含的冲突。
scala> val doublejsv = Json.toJson(4.1)
doublejsv: play.api.libs.json.JsValue = 4.1
scala> Json.fromJson(doublejsv)
<console>:21: error: ambiguous implicit values:
both object IntReads in trait DefaultReads of type play.api.libs.json.Reads.IntReads.type
and object ShortReads in trait DefaultReads of type play.api.libs.json.Reads.ShortReads.type
match expected type play.api.libs.json.Reads[T]
Json.fromJson(doublejsv)
^
答案 0 :(得分:1)
使用显式类型:
val double = Json.fromJson[Double](doublejsv)