Created
April 30, 2015 15:27
-
-
Save gbougeard/0b7972824f95aaeaa9a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class GHUser( | |
login: String, | |
id: Long, | |
avatar_url: String, | |
gravatar_id: Option[String], | |
url: String, | |
html_url: String, | |
followers_url: String, | |
following_url: Option[String], | |
gists_url: Option[String], | |
starred_url: String, | |
subscriptions_url: String, | |
organizations_url: String, | |
repos_url: String, | |
events_url: Option[String], | |
received_events_url: String, | |
`type`: String, | |
site_admin: Boolean | |
) | |
case class GHPullRequestMini(project :String, | |
url: String, | |
title: String, | |
state: String, | |
user: GHUser, | |
body: String, | |
created_at: String, | |
updated_at: String, | |
closed_at: Option[String], | |
merged_at: Option[String], | |
assignee: Option[GHUser], | |
branch: String | |
) | |
implicit val GHUserJsonWrite = { | |
import play.api.data.mapping.json.Writes._ // let's no leak implicits everywhere | |
Write.gen[GHUser, JsObject] | |
} | |
implicit val GHPullRequestMiniJsonWrite = { | |
import play.api.data.mapping.json.Writes._ // let's no leak implicits everywhere | |
Write.gen[GHPullRequestMini, JsObject] | |
} | |
val pullRequests:Seq[GHPullRequestMini] = ... | |
val json = To[Seq[GHPullRequestMini], JsObject](pullRequests) | |
// => could not find implicit value for parameter w: play.api.data.mapping.WriteLike[Seq[models.GHPullRequestMini],play.api.libs.json.JsObject] |
Mouai en fait pour generer le Write
il faut un JsObject
car tu as besoin du Monoid
sur ce type. Par contre pour la Seq
i tu faut une JsValue
du coup il faut que tu type explicitement GHPullRequestMiniJsonWrite
Exemple:
case class Foo(s: String, i: Int)
val foos = Seq(Foo("foo", 1))
implicit val ws: Write[Foo, JsValue] = Write.gen[Foo, JsObject]
scala> To[Seq[Foo], JsValue](foos)
res7: play.api.libs.json.JsValue = [{"s":"foo","i":1}]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
JsValue
c'est bon pour un type simple par pour unecase class
j'ai l'impression.val json = To[Seq[GHPullRequestMini], JsValue](pullRequests) // => could not find implicit value for parameter w: play.api.data.mapping.WriteLike[Seq[models.GHPullRequestMini],play.api.libs.json.JsValue]
du coup il faut que je modifie mes
Write
comme celaWrite.gen[GHPullRequestMini, JsValue] => value ~ is not a member of play.api.data.mapping.Write[String,play.api.libs.json.JsValue] Note: implicit value GHPullRequestMiniJsonWrite is not applicable here because it comes after the application point and it lacks an explicit result type