All Projects → jilen → Play Circe

jilen / Play Circe

Licence: apache-2.0
circe for play

Programming Languages

scala
5932 projects

Projects that are alternatives of or similar to Play Circe

Play Json
The Play JSON library
Stars: ✭ 254 (+167.37%)
Mutual labels:  json, playframework
Play Scala Rest Api Example
Example Play Scala application showing REST API
Stars: ✭ 227 (+138.95%)
Mutual labels:  json, playframework
Jsonmapper
Map nested JSON structures onto PHP classes
Stars: ✭ 1,306 (+1274.74%)
Mutual labels:  json
Swagger Merger
🔗 Merge multiple swagger files into a swagger file, support JSON/YAML.
Stars: ✭ 94 (-1.05%)
Mutual labels:  json
Behat Api Extension
API extension for Behat, used to ease testing of JSON-based APIs
Stars: ✭ 92 (-3.16%)
Mutual labels:  json
Filecontextcore
FileContextCore is a "Database"-Provider for Entity Framework Core and adds the ability to store information in files instead of being limited to databases.
Stars: ✭ 91 (-4.21%)
Mutual labels:  json
Night Config
Powerful java configuration library for toml, yaml, hocon, json and in-memory configurations
Stars: ✭ 93 (-2.11%)
Mutual labels:  json
Catj
Displays JSON files in a flat format.
Stars: ✭ 1,301 (+1269.47%)
Mutual labels:  json
Jsonmasking
Replace fields in json, replacing by something, don't care if property is in depth objects. Very useful to replace passwords credit card number, etc.
Stars: ✭ 95 (+0%)
Mutual labels:  json
Python Training For Network Engineers
Python hands-on training for network engineers. How to automate Junos with Python
Stars: ✭ 92 (-3.16%)
Mutual labels:  json
Restson Rust
Easy-to-use REST client for Rust programming language
Stars: ✭ 93 (-2.11%)
Mutual labels:  json
Api Client Generator
Angular REST API client generator from Swagger YAML or JSON file with camel case settigs
Stars: ✭ 92 (-3.16%)
Mutual labels:  json
Jutil
Command-line utilities for manipulating JSON
Stars: ✭ 91 (-4.21%)
Mutual labels:  json
Json Benchmark
nativejson-benchmark in Rust
Stars: ✭ 93 (-2.11%)
Mutual labels:  json
Go
A high-performance 100% compatible drop-in replacement of "encoding/json"
Stars: ✭ 10,248 (+10687.37%)
Mutual labels:  json
Swurg
Parse OpenAPI documents into Burp Suite for automating OpenAPI-based APIs security assessments (approved by PortSwigger for inclusion in their official BApp Store).
Stars: ✭ 94 (-1.05%)
Mutual labels:  json
Tabtoy
高性能表格数据导出器
Stars: ✭ 1,302 (+1270.53%)
Mutual labels:  json
Spots
🎍 Spots is a cross-platform view controller framework for building component-based UIs
Stars: ✭ 1,310 (+1278.95%)
Mutual labels:  json
Metayaml
A powerful schema validator!
Stars: ✭ 92 (-3.16%)
Mutual labels:  json
Generic Json Swift
A simple Swift library for working with generic JSON structures
Stars: ✭ 95 (+0%)
Mutual labels:  json

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"

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].