-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider adding a BodyWritable[Json] type class instance #36
Comments
@tbinna |
Yes, that's true. It could be a different trait for Play WS. For Play 2.5.x I used the same |
Hey Guys, so is there by now a way or workaround to parse WSReponse bodys to case classes? I tried to write a custom CirceJsonBodyReadables trait by myself, but that did not work out. Maybe I am using it wrong, but I cant just use @tbinna writable trait for that right?
In with my response I am trying to do something like.
But that leads to the following error message:
An ugly solution code be to map the body as String and parse it manually? |
@romanskie I think it would be better not casting to |
@romanskie Also you may define implicit def circeBodyReadable[A: io.circe.Decoder] = BodyReadable[io.circe.Decoder.Result[A]]] { response =>
decode[A](response.body)
} Which will enable parse response to |
I wrote this now: implicit def circeJsonBodyReadable = BodyReadable[io.circe.Json] { response =>
io.circe.parser.parse(response.bodyAsBytes.utf8String) match {
case Left(decodingFailure) => throw decodingFailure
case Right(json) => json
}
} And now I am able to: wsClient.url(btcURL).get().map(response => response.body[Json].as[CryptoCompareResponse]) That was the only solution I could apply. It would be very nice if I just could use the following: wsClient.url(btcURL).get().map(response => response.body[CryptoCompareResponse]) I guess that is what you wanted me to do with your implicit def, but i could not get it to work! |
With the update to Play 2.6 my Play WS clients broke.
Previously body serialization when calling
put
,post
, etc. worked usingplay.api.http.Writable
and type class instanceswritableOf_Json
in Circe.scala did the job.Now play-ws requires a type class
play.api.libs.ws.BodyWritable
which is not included in this project. See https://www.playframework.com/documentation/2.6.x/WSMigration26#ScalaFor now I defined this trait in my project which does the job:
Would be nice to add this to the Circe.scala trait but it requires you to add
play-ws
dependency.The text was updated successfully, but these errors were encountered: