Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play Json Reads and String

I have the following JSON reader in Play 2.3:

import play.api.libs.json._
import play.api.libs.json.Reads._
val airportSearchReads: Reads[String] = (JsPath \ "search").read[String](minLength(3))

and the compiler gives me the error

diverging implicit expansion for type play.api.libs.json.Reads[M]
starting with method ArrayReads in trait DefaultReads

if I use an implicit val I get

 ambiguous implicit values:
 both value uuidReads in trait DefaultReads of type => play.api.libs.json.Reads[java.util.UUID]
 and value airportSearchReads in object AirportSearch of type => play.api.libs.json.Reads[String]
 match expected type play.api.libs.json.Reads[M]

How do I get it to work?

like image 655
elmalto Avatar asked Oct 31 '14 22:10

elmalto


People also ask

What is a JSValue?

You use the JSValue class to convert basic values, such as numbers and strings, between JavaScript and Objective-C or Swift representations to pass data between native code and JavaScript code.


1 Answers

I get a different error, but it works fine for me if I add an explicit type parameter to minLength:

scala> val airportSearchReads: Reads[String] = (JsPath \ "search").read[String](minLength[String](3))
airportSearchReads: play.api.libs.json.Reads[String] = play.api.libs.json.Reads$$anon$8@3fee86da

I think the problem with leaving that up to the compiler is that there are different combinations of implicits in scope that would satisfy the implicit parameter list of minLength.

like image 134
acjay Avatar answered Sep 28 '22 11:09

acjay