play-circe


License

License

GroupId

GroupId

com.dripower
ArtifactId

ArtifactId

play-circe_2.11
Last Version

Last Version

2711.0
Release Date

Release Date

Type

Type

jar
Description

Description

play-circe
play-circe
Project URL

Project URL

https://github.com/jilen/play-circe
Project Organization

Project Organization

com.dripower
Source Code Management

Source Code Management

https://github.com/jilen/play-circe

Download play-circe_2.11

How to add to project

<!-- https://jarcasting.com/artifacts/com.dripower/play-circe_2.11/ -->
<dependency>
    <groupId>com.dripower</groupId>
    <artifactId>play-circe_2.11</artifactId>
    <version>2711.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.dripower/play-circe_2.11/
implementation 'com.dripower:play-circe_2.11:2711.0'
// https://jarcasting.com/artifacts/com.dripower/play-circe_2.11/
implementation ("com.dripower:play-circe_2.11:2711.0")
'com.dripower:play-circe_2.11:jar:2711.0'
<dependency org="com.dripower" name="play-circe_2.11" rev="2711.0">
  <artifact name="play-circe_2.11" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.dripower', module='play-circe_2.11', version='2711.0')
)
libraryDependencies += "com.dripower" % "play-circe_2.11" % "2711.0"
[com.dripower/play-circe_2.11 "2711.0"]

Dependencies

compile (3)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.11.12
io.circe : circe-core_2.11 jar 0.11.1
io.circe : circe-parser_2.11 jar 0.11.1

provided (1)

Group / Artifact Type Version
com.typesafe.play : play_2.11 jar 2.7.0

test (3)

Group / Artifact Type Version
io.circe : circe-generic_2.11 jar 0.11.1
org.scalatestplus.play : scalatestplus-play_2.11 jar 4.0.0
com.typesafe.play : play-ws_2.11 jar 2.7.0

Project Modules

There are no modules declared in this project.

Circe support for playframework

Build codecov

How to get it

  • Add dependency

For play 2.6.x

libraryDependencies += "com.dripower" %% "play-circe" % "2612.0"

For play 2.7.x

libraryDependencies += "com.dripower" %% "play-circe" % "2712.0"

For play 2.8.x

libraryDependencies += "com.dripower" %% "play-circe" % "2812.1"

Usage

package play.api.libs.circe

import io.circe.generic.auto._
import io.circe.syntax._
import play.api._
import play.api.mvc._

class CirceController(val controllerComponents: ControllerComponents) extends BaseController with Circe {

  case class Bar(bar: Int)
  case class Foo(foo: String, bar: Bar)

  val bar = Bar(1)
  val foo = Foo("foo", bar)

  //serve json
  def get = Action {
    Ok(foo.asJson)
  }

  //parse json to case class
  def post = Action(circe.json[Foo]) { implicit request =>
    val isEqual = request.body == foo
    Ok(isEqual.toString)
  }

  def postJson = Action(circe.json) { implicit request =>
    val isEqual = request.body == foo.asJson
    Ok(isEqual.toString)
  }

  def postTolerate = Action(circe.tolerantJson[Foo]) { implicit request =>
    val isEqual = request.body == foo
    Ok(isEqual.toString)
  }

  def postTolerateJson = Action(circe.tolerantJson) { implicit request =>
    val isEqual = request.body == foo.asJson
    Ok(isEqual.toString)
  }
}

FAQ

  • If you want to customize the json output, you can provide an implicit Printer in scope (default is Printer.noSpaces):
import io.circe.Printer

implicit val customPrinter = Printer.spaces2.copy(dropNullValues = true)
  • The Circe totally ignores the configured HttpErrorHandler and just uses DefaultHttpErrorHandler. If this not what you want, simply make a trait to override circeErrorHandler like this
class MyController @Inject() (val errorHandler: HttpErrorHandler, val controllerComponents: ControllerComponents) extends BaseController with Circe {
  override def circeErrorHandler = errorHandler
}

Pre-push Git hook

There's one Git hook included. It's inside the hooks folder and it will run the prep SBT task before pushing to any remote.

This prep task is intended to run all the checks you consider before pushing. At this very moment, it try to compile and check the code style rules with ScalaFmt.

In order to install this hook, just cd hooks and run ./install-hooks.sh.

Versions

Version
2711.0
2611.0
2610.0
2609.2
2609.1
2609.0
2609M2.0
2608.5
2.5-0.10.0
2.5-0.9.0
2.5-0.9.0-M2