import play.api.libs.json.Json
case class User(name: String, age: Int, active: Boolean)
object JsonTest extends App {
implicit val userReads = Json.reads[User] // not found: value JsPath
implicit val userWrites = Json.writes[User] // not found: value JsPath
val daniel = User("daniel", 37, true)
/*
* Multiple markers at this line
* - not enough arguments for method toJson: (implicit tjs: play.api.libs.json.Writes[User])play.api.libs.json.JsValue.
* Unspecified value parameter tjs.
* - No Json deserializer found for type User. Try to implement an implicit Writes or Format for this type.
*/
val userJson = Json.toJson(daniel)
val user = Json.fromJson(userJson)
assert(user == daniel)
}
--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/6PK11GKoIlkJ.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
Multiple markers at this line
- diverging implicit expansion for type play.api.libs.json.Reads[T] starting with method ArrayReads in trait DefaultReads
- ambiguous implicit values: both value userReads in object json of type => play.api.libs.json.Reads[json.User] and object IntReads in trait DefaultReads of type play.api.libs.json.Reads.IntReads.type match expected type play.api.libs.json.Reads[T]
- diverging implicit expansion for type play.api.libs.json.Reads[T] starting with method ArrayReads in trait DefaultReads
- not enough arguments for method fromJson: (implicit fjs: play.api.libs.json.Reads[T])play.api.libs.json.JsResult[T]. Unspecified value parameter fjs.
Anyway, as of this discussion the json stuff is currently subject of refactoring...
import play.api.libs.json._
import play.api.libs.json.util._
// import play.api.libs.json.Reads._
import play.api.libs.json.Writes._
object json {
case class User(name: String, age: Int, active: Boolean)
implicit val userReads = Json.reads[User] //> userReads : play.api.libs.json.Reads[json.User] = play.api.libs.json.Reads$
//| $anon$8@518f5824
implicit val userWrites = Json.writes[User] //> userWrites : play.api.libs.json.OWrites[json.User] = play.api.libs.json.OWr
//| ites$$anon$2@388ee016
val daniel = User("daniel", 37, true) //> daniel : json.User = User(daniel,37,true)
val userJson = Json.toJson(daniel) //> userJson : play.api.libs.json.JsValue = {"name":"daniel","age":37,"active":
//| true}
val user = Json.fromJson(userJson) //> user : play.api.libs.json.JsResult[json.User] = JsSuccess(User(daniel,37,tr
//| ue),)
user.get == daniel //> res0: Boolean = true
--
- Daniel--
Daniel,
Please test again with your case and let see if you still have a pb!
Pascal
Wow - thank you very much!Daniel
--
Git clone master
Go in framework Dir
Run ./build
Then "publish-local" in console
Then point your play alias to bin/play
Run your project with this play
Pascal
Pascal,could you give me a hint how I get the changes of your pull request to my local git repository?
--
Multiple markers at this line
- ambiguous implicit values: both value userReads in object JsonTest of type => play.api.libs.json.Reads[User] and object IntReads in trait DefaultReads of
type play.api.libs.json.Reads.IntReads.type match expected type play.api.libs.json.Reads[T]
- ambiguous implicit values: both value userReads in object JsonTest of type => play.api.libs.json.Reads[User] and object IntReads in trait DefaultReads of
type play.api.libs.json.Reads.IntReads.type match expected type play.api.libs.json.Reads[T]
- diverging implicit expansion for type play.api.libs.json.Reads[T] starting with method ArrayReads in trait DefaultReads
- not enough arguments for method fromJson: (implicit fjs: play.api.libs.json.Reads[T])play.api.libs.json.JsResult[T]. Unspecified value parameter fjs.
- diverging implicit expansion for type play.api.libs.json.Reads[T] starting with method ArrayReads in trait DefaultReads
- not enough arguments for method fromJson: (implicit fjs: play.api.libs.json.Reads[T])play.api.libs.json.JsResult[T]. Unspecified value parameter fjs.
import play.api.libs.json.Json
object json {
case class User(name: String, age: Int, active: Boolean)
implicit val userReads = Json.reads[User] //> userReads : play.api.libs.json.Reads[json.User] = play.api.libs.json.Reads$
//| $anon$8@144aa0ce
implicit val userWrites = Json.writes[User] //> userWrites : play.api.libs.json.OWrites[json.User] = play.api.libs.json.OWr
//| ites$$anon$2@5cac6a45
--
--
Btw - with the current 2.1-RC1 tag (Utils.scala where added to play.api.libs.functional) my Json example (see above) does not work any more (tried all possible combinations of imports)...
--
import play.api.libs.json._
import play.api.libs.json.util._
import play.api.libs.json.Reads._
import play.api.libs.json.Writes._
case class User(name: String, age: Int, active: Boolean)
object JsonTest extends App {
/* value and is not a member of play.api.libs.json.Reads[String]
* Note: implicit value userReads is not applicable here because it comes
* after the application point and it lacks an explicit result type
*/
implicit val userReads = Json.reads[User]
/*
* value and is not a member of play.api.libs.json.OWrites[String]
* Note: implicit value userWrites is not applicable here because it comes
* after the application point and it lacks an explicit result type
*/
implicit val userWrites = Json.writes[User]
val daniel = User("daniel", 37, true)
/*
* Multiple markers at this line
* - No Json deserializer found for type User. Try to implement an implicit Writes or Format for this type.
* - not enough arguments for method toJson: (implicit tjs: play.api.libs.json.Writes[User])play.api.libs.json.JsValue.
* Unspecified value parameter tjs.
* - No Json deserializer found for type User. Try to implement an implicit Writes or Format for this type.
* - not enough arguments for method toJson: (implicit tjs: play.api.libs.json.Writes[User])play.api.libs.json.JsValue.
* Unspecified value parameter tjs.
*/
val userJson = Json.toJson(daniel)
val user = Json.fromJson(userJson)
println(user.get == daniel)
}
import play.api.libs.json._
import play.api.libs.json.util._
import play.api.libs.json.Reads._
import play.api.libs.json.Writes._
but just: (only because you use macros)
import play.api.libs.json.Json
--
argh - ok got it. it works with these imports (as expected) - thx
import play.api.libs.functional.syntax._
import play.api.libs.json._
--
good luck ;)
--
import play.api.test._
import play.api.test.Helpers._
import play.api.libs.json.Json
import models._
import json.JsonFormats._
class JsonFormatsSpec extends Specification {
"JsonFormats" should {
"equals the user jay" in {
val profile = Profile("Jay Cain")
val settings = Settings()
val jay = User("cain...@gmail.com", profile, settings, "hash", None, false)
val userJson = Json.toJson(jay)
val user = Json.fromJson(userJson)
...
}
}
}
it should work with the 2.1 master / rc1 too. Just add these imports and to implicit val's:
Anyway, as of this discussion the json stuff is currently subject of refactoring...
import play.api.libs.json._
import play.api.libs.json.util._
// import play.api.libs.json.Reads._
import play.api.libs.json.Writes._
implicit val userReads = Json.reads[User]
implicit val userWrites = Json.writes[User]
There's a pending pull request which reduces the imports to the minimum...
- Daniel
import play.api.libs.functional.syntax._import play.api.libs.json.util._
(the package has been moved just before releasing RC1)
(FYI in master this import is no more required as well as Writes._)
regards
Pascal
Hi Daniel,I used your latest imports (whithout Read) but I receive the same warnings similar to you, my code is:import play.api.libs.json._import play.api.libs.json.util._import play.api.libs.json.Writes._object AddressBean extends Controller with RestTrait {implicit val addressWrites = Json.writes[Address]implicit val addressReads = Json.reads[Address]
}
warning: value and is not a member of play.api.libs.json.Reads[Option[Int]] Note: implicit value addressReads is notapplicable here because it comes after the application point and it lacks an explicit result typeI'm wondering if you have added anything else to fix these...Basically I have to make this JSON stuff to work with 2.1-RC1 because my project uses scala 2.10 so can't go back to 2.09... Is there any chance to solve this issue?Thanks!
--
Hi
Did you have same for problem with Scala 2.10RC2 ?
Pascal
--
If you use Foo.apply, it should work.
As soon as you create object for case class, case class hidden features are overriden by compiler...
Concerning the macro, I think we could improve it a bit and go around this problem.
Pascal
--
As @mandubian told me, there is a limitation on case class containing one and only one attribute.Maybe this is your case...
--