playjsonsnake

A micro-library that adds snake case support to play-json

License

License

Categories

Categories

JSON Data
GroupId

GroupId

com.beamly
ArtifactId

ArtifactId

playjsonsnake_2.11
Last Version

Last Version

1.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

playjsonsnake
A micro-library that adds snake case support to play-json
Project URL

Project URL

https://github.com/beamly/playjsonsnake
Project Organization

Project Organization

com.beamly
Source Code Management

Source Code Management

https://github.com/beamly/playjsonsnake

Download playjsonsnake_2.11

How to add to project

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

Dependencies

compile (3)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.11.7
org.typelevel : macro-compat_2.11 jar 1.1.1
com.typesafe.play : play-json_2.11 jar 2.4.6

provided (1)

Group / Artifact Type Version
org.scala-lang : scala-compiler jar 2.11.7

test (1)

Group / Artifact Type Version
org.specs2 : specs2-core_2.11 jar 3.6.5

Project Modules

There are no modules declared in this project.

playjsonsnake Apache 2 badge

playjsonsnake is a micro-library that adds snake case support to play-json, the JSON library in Play.

Setup

Add this to your sbt build definitions, such as in build.sbt:

libraryDependencies += "com.beamly" %% "playjsonsnake" % "1.0.1"

For other build systems see the dependency information on Maven Central:

How to Use

Wrap play-json's OFormat (such as one returned by Json.format) with SnakeCaseJson.format.

The returned OFormat will serialise to and deserialise from snake case JSON field names:

scala> :pa
// Entering paste mode (ctrl-D to finish)

import playjsonsnake._
import play.api.libs.json._

final case class Foo(i: Int, abcDefGhi: Int)
object Foo {
  implicit val jsonFormat: OFormat[Foo] = SnakeCaseJson.format(Json.format[Foo])
}

// Exiting paste mode, now interpreting.

import playjsonsnake._
import play.api.libs.json._
defined class Foo
defined object Foo

scala> Json toJson Foo(123, 456)
res0: play.api.libs.json.JsValue = {"i":123,"abc_def_ghi":456}

scala> Json.fromJson[Foo](Json parse """{ "i" : 123, "abc_def_ghi" : 456 }""")
res1: play.api.libs.json.JsResult[Foo] = JsSuccess(Foo(123,456),)

There are also wrappers for Reads and OWrites, in the form of SnakeCaseJson.reads and SnakeCaseJson.writes.

Dependencies

  • Scala 2.11.x or 2.10.x
  • play-json 2.5.x

Licence

Copyright 2016 Beamly

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

com.beamly

Beamly

Beamly - The Show Never Stops

Versions

Version
1.0.2
1.0.1
1.0.0