play-circe-2611


License

License

GroupId

GroupId

com.dripower
ArtifactId

ArtifactId

play-circe-2611_2.12
Last Version

Last Version

0
Release Date

Release Date

Type

Type

jar
Description

Description

play-circe-2611
play-circe-2611
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-2611_2.12

How to add to project

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

Dependencies

compile (3)

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

provided (1)

Group / Artifact Type Version
com.typesafe.play : play_2.12 jar 2.6.21

test (3)

Group / Artifact Type Version
io.circe : circe-generic_2.12 jar 0.11.1
org.scalatestplus.play : scalatestplus-play_2.12 jar 3.1.2
com.typesafe.play : play-ws_2.12 jar 2.6.21

Project Modules

There are no modules declared in this project.

Circe support for playframework

Build Status Codacy Badge Codacy Badge

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"

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
}

Versions

Version
0