....
import play.api.libs.json._import play.api.libs.functional.syntax._
object MyController extends Controller {
....
private val authResponse2authInfo = (
....
(__ \ 'email ).json.copyFrom ((__ \ 'profile \ 'email ).json.pick) and (__ \ 'displayName ).json.copyFrom ((__ \ 'profile \ 'displayName ).json.pick) and (__ \ 'formattedName).json.copyFrom ((__ \ 'profile \ 'name \ 'formatted).json.pick) and (__ \ 'photo ).json.copyFrom ((__ \ 'profile \ 'photo ).json.pick) ) reduce}
could not find implicit value for parameter reducer: play.api.libs.functional.Reducer[play.api.libs.json.JsObject,B]
).reduce[JsObject, JsObject]could not find implicit value for parameter reducer: play.api.libs.functional.Reducer[play.api.libs.json.JsObject,play.api.libs.json.JsObject]import Reads.JsObjectReducer scalacOptions ++= Seq("-feature", "-language:postfixOps")(__ \ 'email).json.copyFrom (
(__ \ 'profile \ 'verifiedEmail).json.pick or
(__ \ 'profile \ 'email).json.pick
)(__ \ 'photo).json.copyFrom((__ \ 'profile \ 'photo).json.pick)[error] ...diverging implicit expansion for type play.api.libs.json.Reads[A]
[error] starting with method ArrayReads in trait DefaultReadsAny assistance on this would be greatly appreciated.Thanks,David
--
Ok... So, I'm starting to figure some of this out. Hurray for scala docs!After adding:import Reads.JsObjectReducer
And then setting the following my Build.scala, project settings:scalacOptions ++= Seq("-feature", "-language:postfixOps")Reduce has begun working.
Now, does anyone know how to make certain paths Optional? As it is, I've discovered that the "or" operator is very useful. Consider:(__ \ 'email).json.copyFrom (
(__ \ 'profile \ 'verifiedEmail).json.pick or
(__ \ 'profile \ 'email).json.pick
)
But what am I supposed to do on the "left hand" side of the equation?
I'm looking for photo to be completely optional here.(__ \ 'photo).json.copyFrom((__ \ 'profile \ 'photo).json.pick)
I've tried using nullable... Seems like it ought to be able to go in there somewhere. But I usually end up getting something like this:
[error] ...diverging implicit expansion for type play.api.libs.json.Reads[A]
[error] starting with method ArrayReads in trait DefaultReadsAny ideas?
--
Hey Pascal,Thank you for the responses.Sorry about the confusion: when I was asking about the "left-hand side", I was referring to making "photo" completely optional. Most of the second message was about documenting how I got reduce working (in case anyone else ran into this) and showing off what I thought was a cool use of Or while implementing a Json transformer.So yeah, I did mean that I wanted "photo" to not appear if it was missing in the original Json. Which, adding the "orElse Reads.pure(Json.obj())" did quite nicely. Thinking about it now, I would also be fine with it being null, or some other value representing None...
Maybe I'm still too used to the idea of marshaling Json into Case Classes.
Something else I've thought of recently. I didn't realize it until earlier in the week, but I don't think I've posted much here before (if at all). So let me introduce myself...I've been very interested in the Play Framework for over a year now, but only really got into it once 2.0 was released. Until recently, I've been able to answer any question I had through thorough Googling. But I'm really excited by the whole Json Coast-to-Coast, Reactive Mongo, and the Iteratees concepts. I also think that combining those concepts with a MVC JS Client could be really powerful.
So, to everyone that's worked on it; thank you for this awesome web development framework. I think that in many respects, Play Framework is leading the way forward for how web applications should be written.
- David P.--